File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 *
You can’t perform that action at this time.
0 commit comments