@@ -41,6 +41,9 @@ discard block |
||
41 | 41 | |
42 | 42 | class OnDuplicateKeyUpdateRule extends ExecRule |
43 | 43 | { |
44 | + /** |
|
45 | + * @param \PhpBoot\DB\Context $context |
|
46 | + */ |
|
44 | 47 | public function __construct($context) |
45 | 48 | { |
46 | 49 | parent::__construct($context); |
@@ -91,8 +94,6 @@ discard block |
||
91 | 94 | * ->onDuplicateKeyUpdate('a=a+1') |
92 | 95 | * => "INSERT INTO table(a,b) VALUES(1,now()) ON DUPLICATE KEY UPDATE a=a+1" |
93 | 96 | * |
94 | - * @param string $column |
|
95 | - * @param mixed $value |
|
96 | 97 | * @return \PhpBoot\DB\rules\basic\ExecRule |
97 | 98 | */ |
98 | 99 | public function onDuplicateKeyUpdate($expr, $_=null) { |
@@ -95,7 +95,7 @@ |
||
95 | 95 | * @param mixed $value |
96 | 96 | * @return \PhpBoot\DB\rules\basic\ExecRule |
97 | 97 | */ |
98 | - public function onDuplicateKeyUpdate($expr, $_=null) { |
|
98 | + public function onDuplicateKeyUpdate($expr, $_ = null) { |
|
99 | 99 | $this->impl->set($this->context, $expr, array_slice(func_get_args(), 1)); |
100 | 100 | return new ExecRule($this->context); |
101 | 101 | } |
@@ -111,6 +111,9 @@ discard block |
||
111 | 111 | |
112 | 112 | class OrderByRule extends LimitRule |
113 | 113 | { |
114 | + /** |
|
115 | + * @param \PhpBoot\DB\Context $context |
|
116 | + */ |
|
114 | 117 | public function __construct($context){ |
115 | 118 | parent::__construct($context); |
116 | 119 | $this->order = new OrderByImpl(); |
@@ -211,7 +214,7 @@ discard block |
||
211 | 214 | * "WHERE a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1" |
212 | 215 | * @param string|array $conditions |
213 | 216 | * //TODO where(callable $query) |
214 | - * @param mixed $_ |
|
217 | + * @param string $_ |
|
215 | 218 | * @return \PhpBoot\DB\rules\select\GroupByRule |
216 | 219 | */ |
217 | 220 | public function where($conditions=null, $_=null) { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param string|false $asDict |
38 | 38 | * @return array |
39 | 39 | */ |
40 | - public function get($asDict=false) { |
|
40 | + public function get($asDict = false) { |
|
41 | 41 | return ExecImpl::get($this->context, $asDict); |
42 | 42 | } |
43 | 43 | |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | * Execute sql and get one response |
52 | 52 | * @return null |
53 | 53 | */ |
54 | - public function getFirst(){ |
|
54 | + public function getFirst() { |
|
55 | 55 | $res = ExecImpl::get($this->context); |
56 | - if(count($res)){ |
|
56 | + if (count($res)) { |
|
57 | 57 | return $res[0]; |
58 | 58 | } |
59 | 59 | return null; |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * @param string $table |
67 | 67 | * @return \PhpBoot\DB\rules\select\JoinRule |
68 | 68 | */ |
69 | - public function from($table, $as=null){ |
|
70 | - FromImpl::from($this->context, $table,$as); |
|
69 | + public function from($table, $as = null) { |
|
70 | + FromImpl::from($this->context, $table, $as); |
|
71 | 71 | return new JoinRule($this->context); |
72 | 72 | } |
73 | 73 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param string $column |
79 | 79 | * @return \PhpBoot\DB\rules\select\GetRule |
80 | 80 | */ |
81 | - public function of($column){ |
|
81 | + public function of($column) { |
|
82 | 82 | ForUpdateOfImpl::of($this->context, $column); |
83 | 83 | return new GetRule($this->context); |
84 | 84 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * forUpdate() => 'FOR UPDATE' |
90 | 90 | * @return \PhpBoot\DB\rules\select\ForUpdateOfRule |
91 | 91 | */ |
92 | - public function forUpdate(){ |
|
92 | + public function forUpdate() { |
|
93 | 93 | ForUpdateImpl::forUpdate($this->context); |
94 | 94 | return new ForUpdateOfRule($this->context); |
95 | 95 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | class OrderByRule extends LimitRule |
113 | 113 | { |
114 | - public function __construct($context){ |
|
114 | + public function __construct($context) { |
|
115 | 115 | parent::__construct($context); |
116 | 116 | $this->order = new OrderByImpl(); |
117 | 117 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param string $order Sql::ORDER_BY_ASC or Sql::ORDER_BY_DESC |
127 | 127 | * @return \PhpBoot\DB\rules\select\OrderByRule |
128 | 128 | */ |
129 | - public function orderBy($column, $order=null) { |
|
129 | + public function orderBy($column, $order = null) { |
|
130 | 130 | $this->order->orderBy($this->context, $column, $order); |
131 | 131 | return $this; |
132 | 132 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @param string $_ |
168 | 168 | * @return \PhpBoot\DB\rules\select\OrderByRule |
169 | 169 | */ |
170 | - public function having($expr, $_=null) { |
|
170 | + public function having($expr, $_ = null) { |
|
171 | 171 | WhereImpl::having($this->context, $expr, array_slice(func_get_args(), 1)); |
172 | 172 | return new OrderByRule($this->context); |
173 | 173 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param mixed $_ |
215 | 215 | * @return \PhpBoot\DB\rules\select\GroupByRule |
216 | 216 | */ |
217 | - public function where($conditions=null, $_=null) { |
|
217 | + public function where($conditions = null, $_ = null) { |
|
218 | 218 | WhereImpl::where($this->context, $conditions, array_slice(func_get_args(), 1)); |
219 | 219 | return new GroupByRule($this->context); |
220 | 220 | } |
@@ -227,8 +227,8 @@ discard block |
||
227 | 227 | * @param string $table |
228 | 228 | * @return \PhpBoot\DB\rules\select\JoinOnRule |
229 | 229 | */ |
230 | - public function join($table){ |
|
231 | - JoinImpl::join($this->context,null, $table); |
|
230 | + public function join($table) { |
|
231 | + JoinImpl::join($this->context, null, $table); |
|
232 | 232 | return new JoinOnRule($this->context); |
233 | 233 | } |
234 | 234 | /** |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | * @param string $table |
237 | 237 | * @return \PhpBoot\DB\rules\select\JoinOnRule |
238 | 238 | */ |
239 | - public function leftJoin($table){ |
|
240 | - JoinImpl::join($this->context,'LEFT', $table); |
|
239 | + public function leftJoin($table) { |
|
240 | + JoinImpl::join($this->context, 'LEFT', $table); |
|
241 | 241 | return new JoinOnRule($this->context); |
242 | 242 | } |
243 | 243 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @return \PhpBoot\DB\rules\select\JoinOnRule |
247 | 247 | */ |
248 | 248 | public function rightJoin($table) { |
249 | - JoinImpl::join($this->context,'RIGHT', $table); |
|
249 | + JoinImpl::join($this->context, 'RIGHT', $table); |
|
250 | 250 | return new JoinOnRule($this->context); |
251 | 251 | } |
252 | 252 | /** |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @return \PhpBoot\DB\rules\select\JoinOnRule |
256 | 256 | */ |
257 | 257 | public function innerJoin($table) { |
258 | - JoinImpl::join($this->context,'INNER', $table); |
|
258 | + JoinImpl::join($this->context, 'INNER', $table); |
|
259 | 259 | return new JoinOnRule($this->context); |
260 | 260 | } |
261 | 261 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @param string $condition |
268 | 268 | * @return \PhpBoot\DB\rules\select\JoinRule |
269 | 269 | */ |
270 | - public function on($condition){ |
|
270 | + public function on($condition) { |
|
271 | 271 | JoinOnImpl::on($this->context, $condition); |
272 | 272 | return new JoinRule($this->context); |
273 | 273 | } |
@@ -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 |
@@ -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 | } |