@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @param ParamMeta[] $paramMates |
17 | 17 | */ |
18 | - public function __construct(array $paramMates=[]){ |
|
18 | + public function __construct(array $paramMates = []) { |
|
19 | 19 | $this->paramMetas = $paramMates; |
20 | 20 | } |
21 | 21 | |
@@ -26,32 +26,32 @@ discard block |
||
26 | 26 | * @param array $reference |
27 | 27 | * @return void |
28 | 28 | */ |
29 | - public function handle(Application $app, Request $request, array &$params, array &$reference){ |
|
29 | + public function handle(Application $app, Request $request, array &$params, array &$reference) { |
|
30 | 30 | |
31 | 31 | $vld = new Validator(); |
32 | 32 | $req = ['request'=>$request]; |
33 | 33 | $requestArray = new ArrayAdaptor($req); |
34 | 34 | $inputs = []; |
35 | - foreach ($this->paramMetas as $k=>$meta){ |
|
36 | - if($meta->isPassedByReference){ |
|
35 | + foreach ($this->paramMetas as $k=>$meta) { |
|
36 | + if ($meta->isPassedByReference) { |
|
37 | 37 | // param PassedByReference is used to output |
38 | 38 | continue; |
39 | 39 | } |
40 | 40 | $source = \JmesPath\search($meta->source, $requestArray); |
41 | - if ($source !== null){ |
|
41 | + if ($source !== null) { |
|
42 | 42 | $source = ArrayAdaptor::strip($source); |
43 | - if($source instanceof ParameterBag){ |
|
43 | + if ($source instanceof ParameterBag) { |
|
44 | 44 | $source = $source->all(); |
45 | 45 | } |
46 | - if($meta->container){ |
|
46 | + if ($meta->container) { |
|
47 | 47 | $inputs[$meta->name] = $meta->container->make($source); |
48 | - }else{ |
|
48 | + }else { |
|
49 | 49 | $inputs[$meta->name] = $source; |
50 | 50 | } |
51 | - if($meta->validation){ |
|
51 | + if ($meta->validation) { |
|
52 | 52 | $vld->rule($meta->validation, $meta->name); |
53 | 53 | } |
54 | - }else{ |
|
54 | + }else { |
|
55 | 55 | $meta->isOptional or \PhpBoot\abort(new BadRequestHttpException("the parameter \"{$meta->source}\" is missing")); |
56 | 56 | $inputs[$meta->name] = $meta->default; |
57 | 57 | } |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | ); |
68 | 68 | |
69 | 69 | $pos = 0; |
70 | - foreach ($this->paramMetas as $meta){ |
|
71 | - if($meta->isPassedByReference){ |
|
70 | + foreach ($this->paramMetas as $meta) { |
|
71 | + if ($meta->isPassedByReference) { |
|
72 | 72 | $params[$pos] = &$reference[$meta->name]; |
73 | - }else{ |
|
73 | + }else { |
|
74 | 74 | $params[$pos] = $inputs[$meta->name]; |
75 | 75 | } |
76 | 76 | $pos++; |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | - public function getParamNames(){ |
|
82 | - return array_map(function($meta){return $meta->name;}, $this->paramMetas); |
|
81 | + public function getParamNames() { |
|
82 | + return array_map(function($meta) {return $meta->name; }, $this->paramMetas); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | 86 | * 获取参数列表 |
87 | 87 | * @return ParamMeta[] |
88 | 88 | */ |
89 | - public function getParamMetas(){ |
|
89 | + public function getParamMetas() { |
|
90 | 90 | return $this->paramMetas; |
91 | 91 | } |
92 | 92 | |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | * @param $name |
96 | 96 | * @return ParamMeta|null |
97 | 97 | */ |
98 | - public function getParamMeta($name){ |
|
99 | - foreach ($this->paramMetas as $meta){ |
|
100 | - if($meta->name == $name){ |
|
98 | + public function getParamMeta($name) { |
|
99 | + foreach ($this->paramMetas as $meta) { |
|
100 | + if ($meta->name == $name) { |
|
101 | 101 | return $meta; |
102 | 102 | } |
103 | 103 | } |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | } |
46 | 46 | if($meta->container){ |
47 | 47 | $inputs[$meta->name] = $meta->container->make($source); |
48 | - }else{ |
|
48 | + } else{ |
|
49 | 49 | $inputs[$meta->name] = $source; |
50 | 50 | } |
51 | 51 | if($meta->validation){ |
52 | 52 | $vld->rule($meta->validation, $meta->name); |
53 | 53 | } |
54 | - }else{ |
|
54 | + } else{ |
|
55 | 55 | $meta->isOptional or \PhpBoot\abort(new BadRequestHttpException("the parameter \"{$meta->source}\" is missing")); |
56 | 56 | $inputs[$meta->name] = $meta->default; |
57 | 57 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | foreach ($this->paramMetas as $meta){ |
71 | 71 | if($meta->isPassedByReference){ |
72 | 72 | $params[$pos] = &$reference[$meta->name]; |
73 | - }else{ |
|
73 | + } else{ |
|
74 | 74 | $params[$pos] = $inputs[$meta->name]; |
75 | 75 | } |
76 | 76 | $pos++; |