@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function eraseMapping($target) |
29 | 29 | { |
30 | - if(!isset($this->mappings[$target])){ |
|
30 | + if (!isset($this->mappings[$target])) { |
|
31 | 31 | return null; |
32 | 32 | } |
33 | 33 | $ori = $this->mappings[$target]; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function getMapping($target) |
43 | 43 | { |
44 | - if(!array_key_exists($target, $this->mappings)){ |
|
44 | + if (!array_key_exists($target, $this->mappings)) { |
|
45 | 45 | return null; |
46 | 46 | } |
47 | 47 | return $this->mappings[$target]; |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function getMappingBySource($source) |
55 | 55 | { |
56 | - foreach ($this->mappings as $k=>$v){ |
|
57 | - if($v->source == $source){ |
|
56 | + foreach ($this->mappings as $k=>$v) { |
|
57 | + if ($v->source == $source) { |
|
58 | 58 | return [$k, $v]; |
59 | 59 | } |
60 | 60 | } |
61 | - return [null,null]; |
|
61 | + return [null, null]; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | |
@@ -75,15 +75,15 @@ discard block |
||
75 | 75 | 'params'=>$params |
76 | 76 | ]; |
77 | 77 | |
78 | - if($return instanceof Response){ //直接返回Response时, 对return不再做映射 |
|
78 | + if ($return instanceof Response) { //直接返回Response时, 对return不再做映射 |
|
79 | 79 | return $return; |
80 | 80 | } |
81 | 81 | $mappings = $this->getMappings(); |
82 | 82 | |
83 | 83 | $output = []; |
84 | - foreach($mappings as $key=>$map){ |
|
84 | + foreach ($mappings as $key=>$map) { |
|
85 | 85 | $val = \JmesPath\search($map->source, $input); |
86 | - if(substr($key, 0, strlen('response.')) == 'response.'){ |
|
86 | + if (substr($key, 0, strlen('response.')) == 'response.') { |
|
87 | 87 | $key = substr($key, strlen('response.')); |
88 | 88 | } |
89 | 89 | ArrayHelper::set($output, $key, $val); |
@@ -21,20 +21,20 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function __invoke(ControllerContainer $container, $ann, EntityContainerBuilder $entityBuilder) |
23 | 23 | { |
24 | - if(!$ann->parent){ |
|
24 | + if (!$ann->parent) { |
|
25 | 25 | //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent route"); |
26 | 26 | return; |
27 | 27 | } |
28 | 28 | $target = $ann->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 route"); |
32 | - return ; |
|
32 | + return; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | $params = new AnnotationParams($ann->description, 2); |
36 | 36 | $type = $doc = null; |
37 | - if(count($params)>0){ |
|
37 | + if (count($params)>0) { |
|
38 | 38 | $type = TypeHint::normalize($params[0], $container->getClassName()); |
39 | 39 | } |
40 | 40 | $doc = $params->getRawParam(1, ''); |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | list($_, $meta) = $route |
43 | 43 | ->getResponseHandler() |
44 | 44 | ->getMappingBySource('return'); |
45 | - if($meta){ |
|
45 | + if ($meta) { |
|
46 | 46 | $meta->description = $doc; |
47 | 47 | $meta->type = $type; |
48 | - $meta->container = $type == 'void'?null:ContainerFactory::create($entityBuilder, $type); |
|
48 | + $meta->container = $type == 'void' ? null : ContainerFactory::create($entityBuilder, $type); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | } |
52 | 52 | \ No newline at end of file |
@@ -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 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | 'DELETE' |
44 | 44 | ]) or \PhpBoot\abort(new AnnotationSyntaxException("unknown method http $httpMethod in {$container->getClassName()}::$target")); |
45 | 45 | //获取方法参数信息 |
46 | - $rfl = new \ReflectionClass($container->getClassName()); |
|
46 | + $rfl = new \ReflectionClass($container->getClassName()); |
|
47 | 47 | $method = $rfl->getMethod($target); |
48 | 48 | $methodParams = $method->getParameters(); |
49 | 49 | |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | $routeParser = new Std(); |
69 | 69 | $uri = $params->getParam(1); |
70 | 70 | $info = $routeParser->parse($uri); //0.4和1.0返回值不同, 不兼容 |
71 | - if(isset($info[0])){ |
|
72 | - foreach ($info[0] as $i){ |
|
73 | - if(is_array($i)) { |
|
71 | + if (isset($info[0])) { |
|
72 | + foreach ($info[0] as $i) { |
|
73 | + if (is_array($i)) { |
|
74 | 74 | $route->addPathParam($i[0]); |
75 | 75 | } |
76 | 76 | } |
@@ -79,31 +79,31 @@ discard block |
||
79 | 79 | $hasRefParam = false; |
80 | 80 | //设置参数列表 |
81 | 81 | $paramsMeta = []; |
82 | - foreach ($methodParams as $param){ |
|
82 | + foreach ($methodParams as $param) { |
|
83 | 83 | $paramName = $param->getName(); |
84 | 84 | $source = "request.$paramName"; |
85 | - if($route->hasPathParam($paramName)){ //参数来自路由 |
|
85 | + if ($route->hasPathParam($paramName)) { //参数来自路由 |
|
86 | 86 | $source = "request.$paramName"; |
87 | - }elseif($httpMethod == 'GET'){ |
|
87 | + }elseif ($httpMethod == 'GET') { |
|
88 | 88 | $source = "request.$paramName"; //GET请求显示指定来自query string |
89 | 89 | } |
90 | 90 | $paramClass = $param->getClass(); |
91 | - if($paramClass){ |
|
91 | + if ($paramClass) { |
|
92 | 92 | $paramClass = $paramClass->getName(); |
93 | 93 | } |
94 | 94 | $entityContainer = ContainerFactory::create($entityBuilder, $paramClass); |
95 | 95 | $meta = new ParamMeta($paramName, |
96 | 96 | $source, |
97 | - $paramClass?:'mixed', |
|
97 | + $paramClass ?: 'mixed', |
|
98 | 98 | $param->isOptional(), |
99 | - $param->isOptional()?$param->getDefaultValue():null, |
|
99 | + $param->isOptional() ? $param->getDefaultValue() : null, |
|
100 | 100 | $param->isPassedByReference(), |
101 | 101 | null, |
102 | 102 | '', |
103 | 103 | $entityContainer |
104 | 104 | ); |
105 | 105 | $paramsMeta[] = $meta; |
106 | - if($meta->isPassedByReference){ |
|
106 | + if ($meta->isPassedByReference) { |
|
107 | 107 | $hasRefParam = true; |
108 | 108 | $responseHandler->setMapping('response.content.'.$meta->name, new ReturnMeta( |
109 | 109 | 'params.'.$meta->name, |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | $requestHandler->setParamMetas($paramsMeta); |
117 | - if(!$hasRefParam){ |
|
118 | - $responseHandler->setMapping('response.content', new ReturnMeta('return','mixed','', new MixedTypeContainer())); |
|
119 | - }else{ |
|
117 | + if (!$hasRefParam) { |
|
118 | + $responseHandler->setMapping('response.content', new ReturnMeta('return', 'mixed', '', new MixedTypeContainer())); |
|
119 | + }else { |
|
120 | 120 | //当存在引用参数作为输出时, 默认将 return 数据绑定的到 data 下, 以防止和引用参数作为输出重叠 |
121 | - $responseHandler->setMapping('response.content.data', new ReturnMeta('return','mixed','', new MixedTypeContainer())); |
|
121 | + $responseHandler->setMapping('response.content.data', new ReturnMeta('return', 'mixed', '', new MixedTypeContainer())); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $source = "request.$paramName"; |
85 | 85 | if($route->hasPathParam($paramName)){ //参数来自路由 |
86 | 86 | $source = "request.$paramName"; |
87 | - }elseif($httpMethod == 'GET'){ |
|
87 | + } elseif($httpMethod == 'GET'){ |
|
88 | 88 | $source = "request.$paramName"; //GET请求显示指定来自query string |
89 | 89 | } |
90 | 90 | $paramClass = $param->getClass(); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $requestHandler->setParamMetas($paramsMeta); |
117 | 117 | if(!$hasRefParam){ |
118 | 118 | $responseHandler->setMapping('response.content', new ReturnMeta('return','mixed','', new MixedTypeContainer())); |
119 | - }else{ |
|
119 | + } else{ |
|
120 | 120 | //当存在引用参数作为输出时, 默认将 return 数据绑定的到 data 下, 以防止和引用参数作为输出重叠 |
121 | 121 | $responseHandler->setMapping('response.content.data', new ReturnMeta('return','mixed','', new MixedTypeContainer())); |
122 | 122 | } |