@@ -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,16 +114,16 @@ 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($this->returnTarget, new ReturnMeta('return','mixed','', new MixedTypeContainer())); |
|
| 121 | + $responseHandler->setMapping($this->returnTarget, new ReturnMeta('return', 'mixed', '', new MixedTypeContainer())); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
| 125 | 125 | $container->addRoute($target, $route); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - public $returnTarget='response.content.data'; |
|
| 128 | + public $returnTarget = 'response.content.data'; |
|
| 129 | 129 | } |
| 130 | 130 | \ No newline at end of file |
@@ -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($this->returnTarget, new ReturnMeta('return','mixed','', new MixedTypeContainer())); |
| 122 | 122 | } |