Skip to content

Commit 2797635

Browse files
committed
add config
1 parent 8a8eb3e commit 2797635

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

src/OpenApi/Handler/Config.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Astral\Serialize\OpenApi\Handler;
6+
7+
use Astral\Serialize\OpenApi\Collections\OpenApiCollection;
8+
use Astral\Serialize\OpenApi\Storage\OpenAPI\ApiInfo;
9+
use Astral\Serialize\OpenApi\Storage\OpenAPI\OpenAPI;
10+
use Astral\Serialize\OpenApi\Storage\OpenAPI\ParameterStorage;
11+
use Astral\Serialize\OpenApi\Storage\OpenAPI\SchemaStorage;
12+
use Exception;
13+
use JsonException;
14+
use ReflectionException;
15+
16+
class Config
17+
{
18+
19+
public static $config;
20+
21+
public static function rootPath(): string
22+
{
23+
return dirname(__DIR__, 3);
24+
}
25+
26+
public static function build()
27+
{
28+
if(self::$config){
29+
return self::$config;
30+
}
31+
32+
$path = self::rootPath().'/.openapi.php';
33+
if(is_file($path)){
34+
self::$config = include $path;
35+
}
36+
else{
37+
self::$config = include dirname(__DIR__, 3).'/.openapi.php';
38+
}
39+
40+
return self::$config;
41+
}
42+
43+
public static function get($key)
44+
{
45+
return self::build()[$key] ?? '';
46+
}
47+
48+
}

src/OpenApi/Handler/Handler.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ public function __construct(
2424
self::$OpenAPI ??= (new OpenAPI())->withApiInfo(new ApiInfo('API Doc',''));
2525
}
2626

27+
public function rootPath(): string
28+
{
29+
return dirname(__DIR__, 3);
30+
}
31+
32+
public function config()
33+
{
34+
$path = $this->rootPath().'/.openapi.php';
35+
if(is_file($path)){
36+
return include $path;
37+
}
38+
39+
return include dirname(__DIR__, 3).'/.openapi.php';
40+
}
41+
2742
/**
2843
* 构建OpenApi结构文档
2944
*

0 commit comments

Comments
 (0)