@@ -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 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use EnableDIAnnotations; |
16 | 16 | |
17 | 17 | protected $settings = array( |
18 | - 'origin' => '*', // Wide Open! |
|
18 | + 'origin' => '*', // Wide Open! |
|
19 | 19 | 'allowMethods' => 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS', |
20 | 20 | ); |
21 | 21 | protected function setOrigin(Request $req, Response $rsp) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | } |
67 | 67 | } |
68 | 68 | else { // Otherwise, use request headers |
69 | - $allowHeaders = $req->headers->get("Access-Control-Request-Headers", null ,false); |
|
69 | + $allowHeaders = $req->headers->get("Access-Control-Request-Headers", null, false); |
|
70 | 70 | } |
71 | 71 | if (isset($allowHeaders)) { |
72 | 72 | $rsp->headers->set('Access-Control-Allow-Headers', $allowHeaders); |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | $response = new Response("", 200); |
100 | 100 | } |
101 | 101 | else { |
102 | - try{ |
|
102 | + try { |
|
103 | 103 | $response = $next($request); |
104 | - }catch(\Exception $e){ |
|
104 | + }catch (\Exception $e) { |
|
105 | 105 | $response = $this->exceptionRenderer->render($e); |
106 | 106 | } |
107 | 107 | } |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | if (is_array($allowHeaders)) { |
65 | 65 | $allowHeaders = implode(", ", $allowHeaders); |
66 | 66 | } |
67 | - } |
|
68 | - else { // Otherwise, use request headers |
|
67 | + } else { // Otherwise, use request headers |
|
69 | 68 | $allowHeaders = $req->headers->get("Access-Control-Request-Headers", null ,false); |
70 | 69 | } |
71 | 70 | if (isset($allowHeaders)) { |
@@ -81,8 +80,7 @@ discard block |
||
81 | 80 | $this->setAllowCredentials($req, $rsp); |
82 | 81 | $this->setAllowMethods($req, $rsp); |
83 | 82 | $this->setAllowHeaders($req, $rsp); |
84 | - } |
|
85 | - else { |
|
83 | + } else { |
|
86 | 84 | $this->setOrigin($req, $rsp); |
87 | 85 | $this->setExposeHeaders($req, $rsp); |
88 | 86 | $this->setAllowCredentials($req, $rsp); |
@@ -97,11 +95,10 @@ discard block |
||
97 | 95 | public function handle(Request $request, \Closure $next) { |
98 | 96 | if ($request->getMethod() == 'OPTIONS') { |
99 | 97 | $response = new Response("", 200); |
100 | - } |
|
101 | - else { |
|
98 | + } else { |
|
102 | 99 | try{ |
103 | 100 | $response = $next($request); |
104 | - }catch(\Exception $e){ |
|
101 | + } catch(\Exception $e){ |
|
105 | 102 | $response = $this->exceptionRenderer->render($e); |
106 | 103 | } |
107 | 104 | } |
@@ -50,10 +50,10 @@ |
||
50 | 50 | * @param callable $call |
51 | 51 | * @return \Symfony\Component\HttpFoundation\Response |
52 | 52 | */ |
53 | - public function handler(Application $app, callable $call){ |
|
54 | - try{ |
|
53 | + public function handler(Application $app, callable $call) { |
|
54 | + try { |
|
55 | 55 | return $call(); |
56 | - }catch (\Exception $e){ |
|
56 | + }catch (\Exception $e) { |
|
57 | 57 | $renderer = $app->get(ExceptionRenderer::class); //TODO 放在这里是否合适 |
58 | 58 | return $renderer->render($e); |
59 | 59 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | public function handler(Application $app, callable $call){ |
54 | 54 | try{ |
55 | 55 | return $call(); |
56 | - }catch (\Exception $e){ |
|
56 | + } catch (\Exception $e){ |
|
57 | 57 | $renderer = $app->get(ExceptionRenderer::class); //TODO 放在这里是否合适 |
58 | 58 | return $renderer->render($e); |
59 | 59 | } |
@@ -21,17 +21,17 @@ discard block |
||
21 | 21 | $paramType = null; |
22 | 22 | $paramName = null; |
23 | 23 | $paramDoc = ''; |
24 | - if(substr($text, 0, 1) == '$'){ //带$前缀的是变量 |
|
24 | + if (substr($text, 0, 1) == '$') { //带$前缀的是变量 |
|
25 | 25 | $params = new AnnotationParams($text, 2); |
26 | 26 | $paramName = substr($params->getParam(0), 1); |
27 | 27 | $paramDoc = $params->getRawParam(1, ''); |
28 | - }else{ |
|
28 | + }else { |
|
29 | 29 | $params = new AnnotationParams($text, 3); |
30 | - if ($params->count() >=2 && substr($params->getParam(1), 0, 1) == '$'){ |
|
30 | + if ($params->count()>=2 && substr($params->getParam(1), 0, 1) == '$') { |
|
31 | 31 | $paramType = $params->getParam(0); //TODO 检测类型是否合法 |
32 | 32 | $paramName = substr($params->getParam(1), 1); |
33 | 33 | $paramDoc = $params->getRawParam(2, ''); |
34 | - }else{ |
|
34 | + }else { |
|
35 | 35 | \PhpBoot\abort(new AnnotationSyntaxException("@param $text syntax error")); |
36 | 36 | } |
37 | 37 | } |
@@ -44,15 +44,15 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function __invoke(ControllerContainer $container, $ann, EntityContainerBuilder $entityBuilder) |
46 | 46 | { |
47 | - if(!$ann->parent){ |
|
47 | + if (!$ann->parent) { |
|
48 | 48 | //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent route"); |
49 | 49 | return; |
50 | 50 | } |
51 | 51 | $target = $ann->parent->name; |
52 | 52 | $route = $container->getRoute($target); |
53 | - if(!$route){ |
|
53 | + if (!$route) { |
|
54 | 54 | //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent route"); |
55 | - return ; |
|
55 | + return; |
|
56 | 56 | } |
57 | 57 | $className = $container->getClassName(); |
58 | 58 | |
@@ -61,18 +61,18 @@ discard block |
||
61 | 61 | $paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
62 | 62 | $paramMeta or \PhpBoot\abort(new AnnotationSyntaxException("$className::$target param $paramName not exist ")); |
63 | 63 | //TODO 检测声明的类型和注释的类型是否匹配 |
64 | - if($paramType){ |
|
65 | - $paramMeta->type = TypeHint::normalize($paramType, $className);//or \PhpBoot\abort(new AnnotationSyntaxException("{$container->getClassName()}::{$ann->parent->name} @{$ann->name} syntax error, param $paramName unknown type:$paramType ")); |
|
64 | + if ($paramType) { |
|
65 | + $paramMeta->type = TypeHint::normalize($paramType, $className); //or \PhpBoot\abort(new AnnotationSyntaxException("{$container->getClassName()}::{$ann->parent->name} @{$ann->name} syntax error, param $paramName unknown type:$paramType ")); |
|
66 | 66 | $container = ContainerFactory::create($entityBuilder, $paramMeta->type); |
67 | 67 | $paramMeta->container = $container; |
68 | 68 | } |
69 | 69 | $paramMeta->description = $paramDoc; |
70 | 70 | |
71 | 71 | $responseHandler = $route->getResponseHandler(); |
72 | - if($paramMeta->isPassedByReference && $responseHandler){ |
|
72 | + if ($paramMeta->isPassedByReference && $responseHandler) { |
|
73 | 73 | $mappings = $responseHandler->getMappings(); |
74 | - foreach ($mappings as $k => $v){ |
|
75 | - if($v->source == 'params.'.$paramMeta->name){ |
|
74 | + foreach ($mappings as $k => $v) { |
|
75 | + if ($v->source == 'params.'.$paramMeta->name) { |
|
76 | 76 | $v->description = $paramMeta->description; |
77 | 77 | $v->type = $paramMeta->type; |
78 | 78 | $v->container = $paramMeta->container; |
@@ -25,13 +25,13 @@ |
||
25 | 25 | $params = new AnnotationParams($text, 2); |
26 | 26 | $paramName = substr($params->getParam(0), 1); |
27 | 27 | $paramDoc = $params->getRawParam(1, ''); |
28 | - }else{ |
|
28 | + } else{ |
|
29 | 29 | $params = new AnnotationParams($text, 3); |
30 | 30 | if ($params->count() >=2 && substr($params->getParam(1), 0, 1) == '$'){ |
31 | 31 | $paramType = $params->getParam(0); //TODO 检测类型是否合法 |
32 | 32 | $paramName = substr($params->getParam(1), 1); |
33 | 33 | $paramDoc = $params->getRawParam(2, ''); |
34 | - }else{ |
|
34 | + } else{ |
|
35 | 35 | \PhpBoot\abort(new AnnotationSyntaxException("@param $text syntax error")); |
36 | 36 | } |
37 | 37 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $handler->setMapping($params[0], $return); |
45 | 45 | } |
46 | 46 | |
47 | - }elseif($ann->parent->name == 'param'){ |
|
47 | + } elseif($ann->parent->name == 'param'){ |
|
48 | 48 | list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description); |
49 | 49 | |
50 | 50 | $paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | ContainerFactory::create($entityBuilder, $paramMeta->type) |
60 | 60 | ) |
61 | 61 | ); |
62 | - }else{ |
|
62 | + } else{ |
|
63 | 63 | $paramMeta->source = $params[0]; |
64 | 64 | } |
65 | 65 | } |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function __invoke(ControllerContainer $container, $ann, EntityContainerBuilder $entityBuilder) |
23 | 23 | { |
24 | - if(!$ann->parent || !$ann->parent->parent){ |
|
24 | + if (!$ann->parent || !$ann->parent->parent) { |
|
25 | 25 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent param/return"); |
26 | 26 | return; |
27 | 27 | } |
28 | 28 | $target = $ann->parent->parent->name; |
29 | 29 | $route = $container->getRoute($target); |
30 | - if(!$route){ |
|
30 | + if (!$route) { |
|
31 | 31 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent param/return"); |
32 | - return ; |
|
32 | + return; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | $params = new AnnotationParams($ann->description, 2); |
@@ -38,20 +38,20 @@ discard block |
||
38 | 38 | |
39 | 39 | $handler = $route->getResponseHandler(); |
40 | 40 | |
41 | - if ($ann->parent->name == 'return'){ |
|
41 | + if ($ann->parent->name == 'return') { |
|
42 | 42 | list($target, $return) = $handler->getMappingBySource('return'); |
43 | - if($return){ |
|
43 | + if ($return) { |
|
44 | 44 | $handler->eraseMapping($target); |
45 | 45 | $handler->setMapping($params[0], $return); |
46 | 46 | } |
47 | 47 | |
48 | - }elseif($ann->parent->name == 'param'){ |
|
48 | + }elseif ($ann->parent->name == 'param') { |
|
49 | 49 | list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description); |
50 | 50 | |
51 | 51 | $paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
52 | - if($paramMeta->isPassedByReference){ |
|
52 | + if ($paramMeta->isPassedByReference) { |
|
53 | 53 | list($target, $ori) = $handler->getMappingBySource('params.'.$paramName); |
54 | - if($ori){ |
|
54 | + if ($ori) { |
|
55 | 55 | $handler->eraseMapping($target); |
56 | 56 | } |
57 | 57 | //输出绑定 |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ContainerFactory::create($entityBuilder, $paramMeta->type) |
64 | 64 | ) |
65 | 65 | ); |
66 | - }else{ |
|
66 | + }else { |
|
67 | 67 | $paramMeta->source = $params[0]; |
68 | 68 | } |
69 | 69 | } |
@@ -19,15 +19,15 @@ |
||
19 | 19 | */ |
20 | 20 | public function __invoke(ControllerContainer $container, $ann) |
21 | 21 | { |
22 | - if(!$ann->parent){ |
|
22 | + if (!$ann->parent) { |
|
23 | 23 | //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent route"); |
24 | 24 | return; |
25 | 25 | } |
26 | 26 | $target = $ann->parent->name; |
27 | 27 | $route = $container->getRoute($target); |
28 | - if(!$route){ |
|
28 | + if (!$route) { |
|
29 | 29 | //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent route"); |
30 | - return ; |
|
30 | + return; |
|
31 | 31 | } |
32 | 32 | $params = new AnnotationParams($ann->description, 2); |
33 | 33 | count($params)>0 or \PhpBoot\abort(new AnnotationSyntaxException("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require at least one param, {$params->count()} given")); |
@@ -18,29 +18,29 @@ |
||
18 | 18 | */ |
19 | 19 | public function __invoke(ControllerContainer $container, $ann) |
20 | 20 | { |
21 | - if(!$ann->parent || !$ann->parent->parent){ |
|
21 | + if (!$ann->parent || !$ann->parent->parent) { |
|
22 | 22 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent parent"); |
23 | 23 | return; |
24 | 24 | } |
25 | 25 | $target = $ann->parent->parent->name; |
26 | 26 | $route = $container->getRoute($target); |
27 | - if(!$route){ |
|
27 | + if (!$route) { |
|
28 | 28 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent parent"); |
29 | - return ; |
|
29 | + return; |
|
30 | 30 | } |
31 | 31 | $params = new AnnotationParams($ann->description, 2); |
32 | 32 | |
33 | 33 | count($params)>0 or \PhpBoot\abort(new AnnotationSyntaxException("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require 1 param, {$params->count()} given")); |
34 | 34 | |
35 | - if($ann->parent->name == 'param'){ |
|
35 | + if ($ann->parent->name == 'param') { |
|
36 | 36 | list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description); |
37 | 37 | |
38 | 38 | $paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
39 | - if($params->count()>1){ |
|
39 | + if ($params->count()>1) { |
|
40 | 40 | $paramMeta->validation = [$params[0], $params[1]]; |
41 | - }else{ |
|
41 | + }else { |
|
42 | 42 | $paramMeta->validation = $params[0]; |
43 | - if($paramMeta->validation) { |
|
43 | + if ($paramMeta->validation) { |
|
44 | 44 | $v = new Validator(); |
45 | 45 | $v->rule($paramMeta->validation, $paramMeta->name); |
46 | 46 | if ($v->hasRule('optional', $paramMeta->name)) { |
@@ -38,7 +38,7 @@ |
||
38 | 38 | $paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
39 | 39 | if($params->count()>1){ |
40 | 40 | $paramMeta->validation = [$params[0], $params[1]]; |
41 | - }else{ |
|
41 | + } else{ |
|
42 | 42 | $paramMeta->validation = $params[0]; |
43 | 43 | if($paramMeta->validation) { |
44 | 44 | $v = new Validator(); |