@@ -13,11 +13,11 @@ discard block |
||
13 | 13 | * @param AnnotationTag[] $children |
14 | 14 | * @param AnnotationBlock|null $parent |
15 | 15 | */ |
16 | - public function __construct($name='', |
|
17 | - $summary='', |
|
18 | - $description='', |
|
19 | - $children=[], |
|
20 | - $parent=null) |
|
16 | + public function __construct($name = '', |
|
17 | + $summary = '', |
|
18 | + $description = '', |
|
19 | + $children = [], |
|
20 | + $parent = null) |
|
21 | 21 | { |
22 | 22 | $this->name = $name; |
23 | 23 | $this->summary = $summary; |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * @var string |
39 | 39 | */ |
40 | - public $description=''; |
|
40 | + public $description = ''; |
|
41 | 41 | /** |
42 | 42 | * @var AnnotationTag[] |
43 | 43 | */ |
44 | - public $children=[]; |
|
44 | + public $children = []; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @var AnnotationTag|null |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | * @param array $children |
14 | 14 | * @param AnnotationBlock|AnnotationTag|null $parent |
15 | 15 | */ |
16 | - public function __construct($name='', |
|
17 | - $description='', |
|
18 | - $children=[], |
|
19 | - $parent=null) |
|
16 | + public function __construct($name = '', |
|
17 | + $description = '', |
|
18 | + $children = [], |
|
19 | + $parent = null) |
|
20 | 20 | { |
21 | 21 | $this->name = $name; |
22 | 22 | $this->description = $description; |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @var string |
33 | 33 | */ |
34 | - public $description=''; |
|
34 | + public $description = ''; |
|
35 | 35 | /** |
36 | 36 | * @var AnnotationBlock[] |
37 | 37 | */ |
38 | - public $children=[]; |
|
38 | + public $children = []; |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @var AnnotationBlock|null |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | } |
33 | 33 | class AnnotationReader implements \ArrayAccess |
34 | 34 | { |
35 | - static public function createDocBlockFactory(){ |
|
35 | + static public function createDocBlockFactory() { |
|
36 | 36 | $fqsenResolver = new FqsenResolver(); |
37 | - $tagFactory = new StandardTagFactory($fqsenResolver,[]); |
|
37 | + $tagFactory = new StandardTagFactory($fqsenResolver, []); |
|
38 | 38 | $descriptionFactory = new DescriptionFactory($tagFactory); |
39 | 39 | $tagFactory->addService($descriptionFactory); |
40 | 40 | $tagFactory->addService(new TypeResolver($fqsenResolver)); |
@@ -53,22 +53,22 @@ discard block |
||
53 | 53 | { |
54 | 54 | $rfl = new \ReflectionClass($className) or \PhpBoot\abort("load class $className failed"); |
55 | 55 | $fileName = $rfl->getFileName(); |
56 | - $key = str_replace('\\','.',self::class).md5($fileName.$className); |
|
56 | + $key = str_replace('\\', '.', self::class).md5($fileName.$className); |
|
57 | 57 | $oldData = null; |
58 | - $cache = new CheckableCache($localCache?:new ApcCache()); |
|
58 | + $cache = new CheckableCache($localCache ?: new ApcCache()); |
|
59 | 59 | $res = $cache->get('ann:'.$key, null, $oldData, false); |
60 | - if($res === null){ |
|
61 | - try{ |
|
60 | + if ($res === null) { |
|
61 | + try { |
|
62 | 62 | $meta = self::readWithoutCache($className); |
63 | - $cache->set($key, $meta, 0, $fileName?new ClassModifiedChecker($className):null); |
|
63 | + $cache->set($key, $meta, 0, $fileName ? new ClassModifiedChecker($className) : null); |
|
64 | 64 | return $meta; |
65 | - }catch (\Exception $e){ |
|
66 | - $cache->set($key, $e->getMessage(), 0, $fileName?new ClassModifiedChecker($className):null); |
|
65 | + }catch (\Exception $e) { |
|
66 | + $cache->set($key, $e->getMessage(), 0, $fileName ? new ClassModifiedChecker($className) : null); |
|
67 | 67 | throw $e; |
68 | 68 | } |
69 | - }elseif(is_string($res)){ |
|
69 | + }elseif (is_string($res)) { |
|
70 | 70 | \PhpBoot\abort($res); |
71 | - }else{ |
|
71 | + }else { |
|
72 | 72 | return $res; |
73 | 73 | } |
74 | 74 | } |
@@ -85,19 +85,19 @@ discard block |
||
85 | 85 | $reader->class->name = $className; |
86 | 86 | |
87 | 87 | //method annotations |
88 | - foreach ($rfl->getMethods() as $i){ |
|
88 | + foreach ($rfl->getMethods() as $i) { |
|
89 | 89 | $block = self::readAnnotationBlock($i->getDocComment()); |
90 | 90 | $block->name = $i->getName(); |
91 | - $reader->methods[$i->getName()]=$block; |
|
91 | + $reader->methods[$i->getName()] = $block; |
|
92 | 92 | } |
93 | 93 | //property annotations |
94 | - foreach ($rfl->getProperties() as $i){ |
|
94 | + foreach ($rfl->getProperties() as $i) { |
|
95 | 95 | if ($i->isStatic()) { |
96 | 96 | continue; |
97 | 97 | } |
98 | 98 | $block = self::readAnnotationBlock($i->getDocComment()); |
99 | 99 | $block->name = $i->getName(); |
100 | - $reader->properties[$i->getName()]=$block; |
|
100 | + $reader->properties[$i->getName()] = $block; |
|
101 | 101 | } |
102 | 102 | while ($rfl = $rfl->getParentClass()) { |
103 | 103 | foreach ($rfl->getProperties(\ReflectionProperty::IS_PRIVATE) as $i) { |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | $block = self::readAnnotationBlock($i->getDocComment()); |
108 | 108 | $block->name = $i->getName(); |
109 | - $reader->properties[$i->getName()]=$block; |
|
109 | + $reader->properties[$i->getName()] = $block; |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | return $reader; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | static private function readAnnotationBlock($doc) |
116 | 116 | { |
117 | 117 | $annBlock = new AnnotationBlock(); |
118 | - if(empty($doc)){ |
|
118 | + if (empty($doc)) { |
|
119 | 119 | return $annBlock; |
120 | 120 | } |
121 | 121 | $docFactory = AnnotationReader::createDocBlockFactory(); |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | $annTag->parent = $annBlock; |
131 | 131 | $annTag->description = strval($desc); |
132 | 132 | $annTag->name = $tag->getName(); |
133 | - $annTag->children=[]; |
|
134 | - if($desc){ |
|
133 | + $annTag->children = []; |
|
134 | + if ($desc) { |
|
135 | 135 | $output = new AnnotationTagsOutput(); |
136 | 136 | $desc->render($output); |
137 | 137 | foreach ($output->tags as $child) { |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | * @var AnnotationBlock[] |
156 | 156 | */ |
157 | 157 | |
158 | - public $methods=[]; |
|
158 | + public $methods = []; |
|
159 | 159 | /** |
160 | 160 | * @var AnnotationBlock[] |
161 | 161 | */ |
162 | - public $properties=[]; |
|
162 | + public $properties = []; |
|
163 | 163 | |
164 | 164 | public function offsetExists($offset) |
165 | 165 | { |
@@ -23,12 +23,12 @@ |
||
23 | 23 | */ |
24 | 24 | static public function register(Application $app, |
25 | 25 | callable $callback = null, |
26 | - $prefix='/docs') |
|
26 | + $prefix = '/docs') |
|
27 | 27 | { |
28 | - $app->addRoute('GET', $prefix.'/swagger.json', function (Application $app)use($callback){ |
|
28 | + $app->addRoute('GET', $prefix.'/swagger.json', function(Application $app)use($callback){ |
|
29 | 29 | $swagger = new Swagger(); |
30 | 30 | $swagger->appendControllers($app, $app->getControllers()); |
31 | - if($callback){ |
|
31 | + if ($callback) { |
|
32 | 32 | $callback($swagger); |
33 | 33 | } |
34 | 34 | return new Response($swagger->toJson()); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | } |
104 | 104 | if (is_array($v) || is_object($v)) { |
105 | 105 | $res[$k] = self::objectToArray($v); |
106 | - } else { |
|
106 | + }else { |
|
107 | 107 | $res[$k] = $v; |
108 | 108 | } |
109 | 109 | } |
@@ -135,21 +135,21 @@ discard block |
||
135 | 135 | //TODO status 重复怎么办 |
136 | 136 | if ($ins instanceof HttpException) { |
137 | 137 | $status = $ins->getStatusCode(); |
138 | - } else { |
|
138 | + }else { |
|
139 | 139 | |
140 | 140 | $status = 500; |
141 | 141 | } |
142 | 142 | if (isset($res[$status])) { |
143 | 143 | //$this->warnings[] = "status response $status has been used for $name, $desc"; |
144 | 144 | $res = $res[$status]; |
145 | - } else { |
|
145 | + }else { |
|
146 | 146 | $res = new ResponseObject(); |
147 | 147 | } |
148 | 148 | $shortName = self::getShortClassName($name); |
149 | 149 | $desc = "$shortName: $desc"; |
150 | 150 | $res->description = implode("\n", [$res->description, $desc]); |
151 | 151 | $error = $app->get(ExceptionRenderer::class)->render($ins)->getContent(); |
152 | - if($error){ |
|
152 | + if ($error) { |
|
153 | 153 | $res->examples = [$shortName => $error]; |
154 | 154 | } |
155 | 155 | //$res->schema = new RefSchemaObject("#/definitions/$name"); |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | { |
209 | 209 | if ($content instanceof ReturnMeta || $content instanceof ParamMeta) { |
210 | 210 | return $this->makeExample($content->container); |
211 | - }elseif ($content instanceof TypeContainerInterface){ |
|
211 | + }elseif ($content instanceof TypeContainerInterface) { |
|
212 | 212 | return $content->makeExample(); |
213 | - }elseif(is_array($content)) { |
|
213 | + }elseif (is_array($content)) { |
|
214 | 214 | $res = []; |
215 | 215 | foreach ($content as $k => $v) { |
216 | 216 | $res[$k] = $this->makeExample($v); |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | array $arr) |
235 | 235 | { |
236 | 236 | $className = self::getShortClassName($controller->getClassName()); |
237 | - $name = $className . ucfirst($action) . 'Res'; |
|
237 | + $name = $className.ucfirst($action).'Res'; |
|
238 | 238 | |
239 | 239 | $schema = new SimpleModelSchemaObject(); |
240 | 240 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | } elseif ($v->container instanceof EntityContainer) { |
253 | 253 | $sub = $this->getRefSchema($app, $controller, $action, $route, $v->container); |
254 | 254 | //TODO array for validation |
255 | - } else { |
|
255 | + }else { |
|
256 | 256 | $sub = new PrimitiveSchemaObject(); |
257 | 257 | $sub->type = self::mapType($v->type); |
258 | 258 | self::mapValidation($v->validation, $sub); |
@@ -264,14 +264,14 @@ discard block |
||
264 | 264 | $schema->required[] = $k; |
265 | 265 | } |
266 | 266 | $schema->properties[$k] = $sub; |
267 | - } else { |
|
267 | + }else { |
|
268 | 268 | //TODO how to do? |
269 | 269 | } |
270 | 270 | } |
271 | 271 | $unused = $name; |
272 | 272 | $tempId = 0; |
273 | 273 | while (isset($this->definitions[$unused])) { |
274 | - $unused = $name . $tempId; |
|
274 | + $unused = $name.$tempId; |
|
275 | 275 | $tempId++; |
276 | 276 | } |
277 | 277 | $this->definitions[$unused] = $schema; |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | || $route->getMethod() == 'PATCH' |
342 | 342 | ) { |
343 | 343 | $in = 'body'; |
344 | - } else { |
|
344 | + }else { |
|
345 | 345 | $in = 'query'; |
346 | 346 | } |
347 | 347 | } |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | } elseif ($param->container instanceof EntityContainer) { |
353 | 353 | $paramSchema = $this->getRefSchema($app, $controller, $action, $route, $param->container); |
354 | 354 | //TODO array for validation |
355 | - } else { |
|
355 | + }else { |
|
356 | 356 | $paramSchema = new PrimitiveSchemaObject(); |
357 | 357 | $paramSchema->type = self::mapType($param->type); |
358 | 358 | self::mapValidation($param->validation, $paramSchema); |
@@ -363,10 +363,10 @@ discard block |
||
363 | 363 | $paramSchema->default = $param->default; |
364 | 364 | $paramSchema->required = !$param->isOptional; |
365 | 365 | $parameters[] = $paramSchema; |
366 | - } else { |
|
366 | + }else { |
|
367 | 367 | if (!$name) { |
368 | 368 | $body = $param; |
369 | - } else { |
|
369 | + }else { |
|
370 | 370 | ArrayHelper::set($body, $name, $param); |
371 | 371 | } |
372 | 372 | |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | $paramSchema->in = 'body'; |
379 | 379 | if (is_array($body)) { |
380 | 380 | $paramSchema->schema = $this->makeTempSchema($app, $controller, $action, $route, $body); |
381 | - } else { |
|
381 | + }else { |
|
382 | 382 | $paramSchema->schema = $this->getAnySchema($app, $controller, $action, $route, $body->container); |
383 | 383 | } |
384 | 384 | |
@@ -405,8 +405,8 @@ discard block |
||
405 | 405 | } elseif ($container instanceof ScalarTypeContainer) { |
406 | 406 | $schema = new PrimitiveSchemaObject(); |
407 | 407 | $schema->type = self::mapType($container->getType()); |
408 | - } elseif($container == null){ |
|
409 | - $schema = null ;//new PrimitiveSchemaObject(); |
|
408 | + } elseif ($container == null) { |
|
409 | + $schema = null; //new PrimitiveSchemaObject(); |
|
410 | 410 | //$schema->type = null; |
411 | 411 | }else { |
412 | 412 | $schema = new PrimitiveSchemaObject(); |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | } elseif ($itemContainer instanceof ScalarTypeContainer) { |
439 | 439 | $itemSchema = new PrimitiveSchemaObject(); |
440 | 440 | $itemSchema->type = self::mapType($itemContainer->getType()); |
441 | - } else { |
|
441 | + }else { |
|
442 | 442 | $itemSchema = new PrimitiveSchemaObject(); |
443 | 443 | //$itemSchema->type = 'mixed'; |
444 | 444 | } |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | $propertySchema = $this->getRefSchema($app, $controller, $action, $route, $property->container); |
465 | 465 | } elseif ($property->container instanceof ArrayContainer) { |
466 | 466 | $propertySchema = $this->getArraySchema($app, $controller, $action, $route, $property->container); |
467 | - } else { |
|
467 | + }else { |
|
468 | 468 | $propertySchema = new PrimitiveSchemaObject(); |
469 | 469 | $propertySchema->type = self::mapType($property->type); |
470 | 470 | $propertySchema->description = implode("\n", [$property->summary, $property->description]); |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | */ |
485 | 485 | static public function mapValidation($v, PrimitiveSchemaObject $schemaObject) |
486 | 486 | { |
487 | - if(!$v){ |
|
487 | + if (!$v) { |
|
488 | 488 | return $schemaObject; |
489 | 489 | } |
490 | 490 | $rules = explode('|', $v); |
@@ -500,15 +500,15 @@ discard block |
||
500 | 500 | } elseif ($rule == 'lengthBetween' && isset($params[0]) && isset($params[1])) { |
501 | 501 | $schemaObject->minLength = intval($params[0]); |
502 | 502 | $schemaObject->maxLength = intval($params[1]); |
503 | - } elseif ($rule == 'lengthMin'&& isset($params[0])) { |
|
503 | + } elseif ($rule == 'lengthMin' && isset($params[0])) { |
|
504 | 504 | $schemaObject->minLength = intval($params[0]); |
505 | - } elseif ($rule == 'lengthMax'&& isset($params[0])) { |
|
505 | + } elseif ($rule == 'lengthMax' && isset($params[0])) { |
|
506 | 506 | $schemaObject->maxLength = intval($params[0]); |
507 | - } elseif ($rule == 'min'&& isset($params[0])) { |
|
507 | + } elseif ($rule == 'min' && isset($params[0])) { |
|
508 | 508 | $schemaObject->minimum = floatval($params[0]); |
509 | - } elseif ($rule == 'max'&& isset($params[0])) { |
|
509 | + } elseif ($rule == 'max' && isset($params[0])) { |
|
510 | 510 | $schemaObject->maximum = floatval($params[0]); |
511 | - } elseif ($rule == 'regex'&& isset($params[0])) { |
|
511 | + } elseif ($rule == 'regex' && isset($params[0])) { |
|
512 | 512 | $schemaObject->pattern = $params[0]; |
513 | 513 | } elseif ($rule == 'optional') { |
514 | 514 | $schemaObject->required = false; |
@@ -64,12 +64,12 @@ |
||
64 | 64 | * The value overrides the Swagger Object schemes definition. |
65 | 65 | * @var string[] |
66 | 66 | */ |
67 | - public $schemes=['http']; |
|
67 | + public $schemes = ['http']; |
|
68 | 68 | /** |
69 | 69 | * Declares this operation to be deprecated. Usage of the declared operation should be refrained. Default value is false. |
70 | 70 | * @var bool |
71 | 71 | */ |
72 | - public $deprecated=false; |
|
72 | + public $deprecated = false; |
|
73 | 73 | /** |
74 | 74 | * A declaration of which security schemes are applied for this operation. The list of values describes |
75 | 75 | * alternative security schemes that can be used (that is, there is a logical OR between the security |
@@ -52,18 +52,18 @@ |
||
52 | 52 | * A list of MIME types the APIs can produce. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under Mime Types. |
53 | 53 | * @var string[] |
54 | 54 | */ |
55 | - public $produces= ['application/json']; |
|
55 | + public $produces = ['application/json']; |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @var PathItemObject[] |
59 | 59 | */ |
60 | - public $paths=[]; |
|
60 | + public $paths = []; |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * An object to hold data types produced and consumed by operations. |
64 | 64 | * @var RefSchemaObject[]|SimpleModelSchemaObject[]|PrimitiveSchemaObject[]|ArraySchemaObject[] |
65 | 65 | */ |
66 | - public $definitions=[]; |
|
66 | + public $definitions = []; |
|
67 | 67 | /** |
68 | 68 | * An object to hold parameters that can be used across operations. This property does not define global |
69 | 69 | * parameters for all operations. |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * Required. The title of the application. |
10 | 10 | * @var string |
11 | 11 | */ |
12 | - public $title=''; |
|
12 | + public $title = ''; |
|
13 | 13 | /** |
14 | 14 | * A short description of the application. GFM syntax can be used for rich text representation |
15 | 15 | * @var string |
@@ -34,5 +34,5 @@ discard block |
||
34 | 34 | * Required Provides the version of the application API (not to be confused with the specification version) |
35 | 35 | * @var string |
36 | 36 | */ |
37 | - public $version=''; |
|
37 | + public $version = ''; |
|
38 | 38 | } |
39 | 39 | \ No newline at end of file |
@@ -10,7 +10,7 @@ |
||
10 | 10 | * representation. |
11 | 11 | * @var string |
12 | 12 | */ |
13 | - public $description=''; |
|
13 | + public $description = ''; |
|
14 | 14 | /** |
15 | 15 | * A definition of the response structure. It can be a primitive, an array or an object. If this field |
16 | 16 | * does not exist, it means no content is returned as part of the response. As an extension to the Schema |