@@ -24,6 +24,9 @@ |
||
24 | 24 | |
25 | 25 | class UpdateSetRule extends WhereRule |
26 | 26 | { |
27 | + /** |
|
28 | + * @param \PhpBoot\DB\Context $context |
|
29 | + */ |
|
27 | 30 | public function __construct($context){ |
28 | 31 | parent::__construct($context); |
29 | 32 | $this->impl = new UpdateSetImpl(); |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | class UpdateSetRule extends WhereRule |
26 | 26 | { |
27 | - public function __construct($context){ |
|
27 | + public function __construct($context) { |
|
28 | 28 | parent::__construct($context); |
29 | 29 | $this->impl = new UpdateSetImpl(); |
30 | 30 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @param mixed $_ |
56 | 56 | * @return \PhpBoot\DB\rules\update\UpdateSetRule |
57 | 57 | */ |
58 | - public function setExpr($expr, $_=null) { |
|
58 | + public function setExpr($expr, $_ = null) { |
|
59 | 59 | $this->impl->setExpr($this->context, $expr, array_slice(func_get_args(), 1)); |
60 | 60 | return $this; |
61 | 61 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | - * @param $object |
|
91 | + * @param Swagger $object |
|
92 | 92 | * @return array |
93 | 93 | */ |
94 | 94 | static public function objectToArray($object) |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * @param Application $app |
115 | 115 | * @param ControllerContainer $controller |
116 | - * @param $action |
|
116 | + * @param integer $action |
|
117 | 117 | * @param Route $route |
118 | 118 | * @return array |
119 | 119 | */ |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | /** |
163 | 163 | * @param Application $app |
164 | 164 | * @param ControllerContainer $controller |
165 | - * @param $action |
|
165 | + * @param integer $action |
|
166 | 166 | * @param Route $route |
167 | 167 | * @return null|ResponseObject |
168 | 168 | */ |
@@ -299,6 +299,9 @@ discard block |
||
299 | 299 | return new RefSchemaObject("#/definitions/$name"); |
300 | 300 | } |
301 | 301 | |
302 | + /** |
|
303 | + * @param integer $action |
|
304 | + */ |
|
302 | 305 | public function getParamsSchema(Application $app, |
303 | 306 | ControllerContainer $controller, |
304 | 307 | $action, |
@@ -21,7 +21,6 @@ |
||
21 | 21 | use PhpBoot\Metas\ParamMeta; |
22 | 22 | use PhpBoot\Metas\ReturnMeta; |
23 | 23 | use PhpBoot\Utils\ArrayHelper; |
24 | -use PhpBoot\Validator\Validator; |
|
25 | 24 | use Symfony\Component\HttpKernel\Exception\HttpException; |
26 | 25 | |
27 | 26 | class Swagger extends SwaggerObject |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | * @return RefSchemaObject |
229 | 229 | */ |
230 | 230 | public function makeTempSchema(Application $app, |
231 | - ControllerContainer $controller, |
|
232 | - $action, |
|
233 | - Route $route, |
|
234 | - array $arr) |
|
231 | + ControllerContainer $controller, |
|
232 | + $action, |
|
233 | + Route $route, |
|
234 | + array $arr) |
|
235 | 235 | { |
236 | 236 | $className = self::getShortClassName($controller->getClassName()); |
237 | 237 | $name = $className . ucfirst($action) . 'Res'; |
@@ -287,10 +287,10 @@ discard block |
||
287 | 287 | * @return RefSchemaObject |
288 | 288 | */ |
289 | 289 | public function getRefSchema(Application $app, |
290 | - ControllerContainer $controller, |
|
291 | - $action, |
|
292 | - Route $route, |
|
293 | - EntityContainer $container) |
|
290 | + ControllerContainer $controller, |
|
291 | + $action, |
|
292 | + Route $route, |
|
293 | + EntityContainer $container) |
|
294 | 294 | { |
295 | 295 | $name = $container->getClassName(); |
296 | 296 | if (!isset($this->definitions[$name])) { |
@@ -424,10 +424,10 @@ discard block |
||
424 | 424 | * @return ArraySchemaObject |
425 | 425 | */ |
426 | 426 | public function getArraySchema(Application $app, |
427 | - ControllerContainer $controller, |
|
428 | - $action, |
|
429 | - Route $route, |
|
430 | - ArrayContainer $container) |
|
427 | + ControllerContainer $controller, |
|
428 | + $action, |
|
429 | + Route $route, |
|
430 | + ArrayContainer $container) |
|
431 | 431 | { |
432 | 432 | $schema = new ArraySchemaObject(); |
433 | 433 | $itemContainer = $container->getContainer(); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | } |
104 | 104 | if (is_array($v) || is_object($v)) { |
105 | 105 | $res[$k] = self::objectToArray($v); |
106 | - } else { |
|
106 | + }else { |
|
107 | 107 | $res[$k] = $v; |
108 | 108 | } |
109 | 109 | } |
@@ -135,21 +135,21 @@ discard block |
||
135 | 135 | //TODO status 重复怎么办 |
136 | 136 | if ($ins instanceof HttpException) { |
137 | 137 | $status = $ins->getStatusCode(); |
138 | - } else { |
|
138 | + }else { |
|
139 | 139 | |
140 | 140 | $status = 500; |
141 | 141 | } |
142 | 142 | if (isset($res[$status])) { |
143 | 143 | //$this->warnings[] = "status response $status has been used for $name, $desc"; |
144 | 144 | $res = $res[$status]; |
145 | - } else { |
|
145 | + }else { |
|
146 | 146 | $res = new ResponseObject(); |
147 | 147 | } |
148 | 148 | $shortName = self::getShortClassName($name); |
149 | 149 | $desc = "$shortName: $desc"; |
150 | 150 | $res->description = implode("\n", [$res->description, $desc]); |
151 | 151 | $error = $app->get(ExceptionRenderer::class)->render($ins)->getContent(); |
152 | - if($error){ |
|
152 | + if ($error) { |
|
153 | 153 | $res->examples = [$shortName => $error]; |
154 | 154 | } |
155 | 155 | //$res->schema = new RefSchemaObject("#/definitions/$name"); |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | { |
209 | 209 | if ($content instanceof ReturnMeta || $content instanceof ParamMeta) { |
210 | 210 | return $this->makeExample($content->container); |
211 | - }elseif ($content instanceof TypeContainerInterface){ |
|
211 | + }elseif ($content instanceof TypeContainerInterface) { |
|
212 | 212 | return $content->makeExample(); |
213 | - }elseif(is_array($content)) { |
|
213 | + }elseif (is_array($content)) { |
|
214 | 214 | $res = []; |
215 | 215 | foreach ($content as $k => $v) { |
216 | 216 | $res[$k] = $this->makeExample($v); |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | array $arr) |
235 | 235 | { |
236 | 236 | $className = self::getShortClassName($controller->getClassName()); |
237 | - $name = $className . ucfirst($action) . 'Res'; |
|
237 | + $name = $className.ucfirst($action).'Res'; |
|
238 | 238 | |
239 | 239 | $schema = new SimpleModelSchemaObject(); |
240 | 240 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | } elseif ($v->container instanceof EntityContainer) { |
253 | 253 | $sub = $this->getRefSchema($app, $controller, $action, $route, $v->container); |
254 | 254 | //TODO array for validation |
255 | - } else { |
|
255 | + }else { |
|
256 | 256 | $sub = new PrimitiveSchemaObject(); |
257 | 257 | $sub->type = self::mapType($v->type); |
258 | 258 | self::mapValidation($v->validation, $sub); |
@@ -264,14 +264,14 @@ discard block |
||
264 | 264 | $schema->required[] = $k; |
265 | 265 | } |
266 | 266 | $schema->properties[$k] = $sub; |
267 | - } else { |
|
267 | + }else { |
|
268 | 268 | //TODO how to do? |
269 | 269 | } |
270 | 270 | } |
271 | 271 | $unused = $name; |
272 | 272 | $tempId = 0; |
273 | 273 | while (isset($this->definitions[$unused])) { |
274 | - $unused = $name . $tempId; |
|
274 | + $unused = $name.$tempId; |
|
275 | 275 | $tempId++; |
276 | 276 | } |
277 | 277 | $this->definitions[$unused] = $schema; |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | || $route->getMethod() == 'PATCH' |
342 | 342 | ) { |
343 | 343 | $in = 'body'; |
344 | - } else { |
|
344 | + }else { |
|
345 | 345 | $in = 'query'; |
346 | 346 | } |
347 | 347 | } |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | } elseif ($param->container instanceof EntityContainer) { |
353 | 353 | $paramSchema = $this->getRefSchema($app, $controller, $action, $route, $param->container); |
354 | 354 | //TODO array for validation |
355 | - } else { |
|
355 | + }else { |
|
356 | 356 | $paramSchema = new PrimitiveSchemaObject(); |
357 | 357 | $paramSchema->type = self::mapType($param->type); |
358 | 358 | self::mapValidation($param->validation, $paramSchema); |
@@ -363,10 +363,10 @@ discard block |
||
363 | 363 | $paramSchema->default = $param->default; |
364 | 364 | $paramSchema->required = !$param->isOptional; |
365 | 365 | $parameters[] = $paramSchema; |
366 | - } else { |
|
366 | + }else { |
|
367 | 367 | if (!$name) { |
368 | 368 | $body = $param; |
369 | - } else { |
|
369 | + }else { |
|
370 | 370 | ArrayHelper::set($body, $name, $param); |
371 | 371 | } |
372 | 372 | |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | $paramSchema->in = 'body'; |
379 | 379 | if (is_array($body)) { |
380 | 380 | $paramSchema->schema = $this->makeTempSchema($app, $controller, $action, $route, $body); |
381 | - } else { |
|
381 | + }else { |
|
382 | 382 | $paramSchema->schema = $this->getAnySchema($app, $controller, $action, $route, $body->container); |
383 | 383 | } |
384 | 384 | |
@@ -405,8 +405,8 @@ discard block |
||
405 | 405 | } elseif ($container instanceof ScalarTypeContainer) { |
406 | 406 | $schema = new PrimitiveSchemaObject(); |
407 | 407 | $schema->type = self::mapType($container->getType()); |
408 | - } elseif($container == null){ |
|
409 | - $schema = null ;//new PrimitiveSchemaObject(); |
|
408 | + } elseif ($container == null) { |
|
409 | + $schema = null; //new PrimitiveSchemaObject(); |
|
410 | 410 | //$schema->type = null; |
411 | 411 | }else { |
412 | 412 | $schema = new PrimitiveSchemaObject(); |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | } elseif ($itemContainer instanceof ScalarTypeContainer) { |
439 | 439 | $itemSchema = new PrimitiveSchemaObject(); |
440 | 440 | $itemSchema->type = self::mapType($itemContainer->getType()); |
441 | - } else { |
|
441 | + }else { |
|
442 | 442 | $itemSchema = new PrimitiveSchemaObject(); |
443 | 443 | //$itemSchema->type = 'mixed'; |
444 | 444 | } |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | $propertySchema = $this->getRefSchema($app, $controller, $action, $route, $property->container); |
465 | 465 | } elseif ($property->container instanceof ArrayContainer) { |
466 | 466 | $propertySchema = $this->getArraySchema($app, $controller, $action, $route, $property->container); |
467 | - } else { |
|
467 | + }else { |
|
468 | 468 | $propertySchema = new PrimitiveSchemaObject(); |
469 | 469 | $propertySchema->type = self::mapType($property->type); |
470 | 470 | $propertySchema->description = implode("\n", [$property->summary, $property->description]); |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | */ |
485 | 485 | static public function mapValidation($v, PrimitiveSchemaObject $schemaObject) |
486 | 486 | { |
487 | - if(!$v){ |
|
487 | + if (!$v) { |
|
488 | 488 | return $schemaObject; |
489 | 489 | } |
490 | 490 | $rules = explode('|', $v); |
@@ -500,15 +500,15 @@ discard block |
||
500 | 500 | } elseif ($rule == 'lengthBetween' && isset($params[0]) && isset($params[1])) { |
501 | 501 | $schemaObject->minLength = intval($params[0]); |
502 | 502 | $schemaObject->maxLength = intval($params[1]); |
503 | - } elseif ($rule == 'lengthMin'&& isset($params[0])) { |
|
503 | + } elseif ($rule == 'lengthMin' && isset($params[0])) { |
|
504 | 504 | $schemaObject->minLength = intval($params[0]); |
505 | - } elseif ($rule == 'lengthMax'&& isset($params[0])) { |
|
505 | + } elseif ($rule == 'lengthMax' && isset($params[0])) { |
|
506 | 506 | $schemaObject->maxLength = intval($params[0]); |
507 | - } elseif ($rule == 'min'&& isset($params[0])) { |
|
507 | + } elseif ($rule == 'min' && isset($params[0])) { |
|
508 | 508 | $schemaObject->minimum = floatval($params[0]); |
509 | - } elseif ($rule == 'max'&& isset($params[0])) { |
|
509 | + } elseif ($rule == 'max' && isset($params[0])) { |
|
510 | 510 | $schemaObject->maximum = floatval($params[0]); |
511 | - } elseif ($rule == 'regex'&& isset($params[0])) { |
|
511 | + } elseif ($rule == 'regex' && isset($params[0])) { |
|
512 | 512 | $schemaObject->pattern = $params[0]; |
513 | 513 | } elseif ($rule == 'optional') { |
514 | 514 | $schemaObject->required = false; |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | { |
209 | 209 | if ($content instanceof ReturnMeta || $content instanceof ParamMeta) { |
210 | 210 | return $this->makeExample($content->container); |
211 | - }elseif ($content instanceof TypeContainerInterface){ |
|
211 | + } elseif ($content instanceof TypeContainerInterface){ |
|
212 | 212 | return $content->makeExample(); |
213 | - }elseif(is_array($content)) { |
|
213 | + } elseif(is_array($content)) { |
|
214 | 214 | $res = []; |
215 | 215 | foreach ($content as $k => $v) { |
216 | 216 | $res[$k] = $this->makeExample($v); |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | } elseif($container == null){ |
409 | 409 | $schema = null ;//new PrimitiveSchemaObject(); |
410 | 410 | //$schema->type = null; |
411 | - }else { |
|
411 | + } else { |
|
412 | 412 | $schema = new PrimitiveSchemaObject(); |
413 | 413 | //$schema->type = 'mixed'; |
414 | 414 | } |
@@ -2,7 +2,6 @@ |
||
2 | 2 | |
3 | 3 | namespace PhpBoot\ORM; |
4 | 4 | |
5 | -use DI\Container; |
|
6 | 5 | use DI\FactoryInterface; |
7 | 6 | use Doctrine\Common\Cache\Cache; |
8 | 7 | use PhpBoot\DI\DIContainerBuilder; |
@@ -16,7 +16,7 @@ |
||
16 | 16 | |
17 | 17 | class ModelContainerBuilder extends EntityContainerBuilder |
18 | 18 | { |
19 | - static $DEFAULT_ANNOTATIONS=[ |
|
19 | + static $DEFAULT_ANNOTATIONS = [ |
|
20 | 20 | [ClassAnnotationHandler::class, 'class'], |
21 | 21 | [PKAnnotationHandler::class, "class.children[?name=='pk']"], |
22 | 22 | [TableAnnotationHandler::class, "class.children[?name=='table']"], |
@@ -5,6 +5,9 @@ discard block |
||
5 | 5 | */ |
6 | 6 | class AnnotationParams implements \Countable, \ArrayAccess |
7 | 7 | { |
8 | + /** |
|
9 | + * @param integer $limit |
|
10 | + */ |
|
8 | 11 | public function __construct($text, $limit) |
9 | 12 | { |
10 | 13 | if($limit == 1){ |
@@ -142,6 +145,12 @@ discard block |
||
142 | 145 | } |
143 | 146 | } |
144 | 147 | |
148 | + /** |
|
149 | + * @param integer $pos |
|
150 | + * @param string $default |
|
151 | + * |
|
152 | + * @return string |
|
153 | + */ |
|
145 | 154 | public function getRawParam($pos, $default = null) |
146 | 155 | { |
147 | 156 | if(isset($this->rawParams[$pos])){ |
@@ -151,6 +160,9 @@ discard block |
||
151 | 160 | } |
152 | 161 | } |
153 | 162 | |
163 | + /** |
|
164 | + * @param boolean $ignoreError |
|
165 | + */ |
|
154 | 166 | private function stripSlashes($text, $ignoreError) |
155 | 167 | { |
156 | 168 | if(strlen($text)>=2 && substr($text,0,1) == '"'){ |
@@ -7,31 +7,31 @@ discard block |
||
7 | 7 | { |
8 | 8 | public function __construct($text, $limit) |
9 | 9 | { |
10 | - if($limit == 1){ |
|
10 | + if ($limit == 1) { |
|
11 | 11 | $this->rawParams[] = $text; |
12 | 12 | return; |
13 | 13 | } |
14 | - if($limit <= 0){ |
|
14 | + if ($limit<=0) { |
|
15 | 15 | return; |
16 | 16 | } |
17 | 17 | $text = ltrim($text); |
18 | 18 | $pos = 0; |
19 | 19 | $state = 'stateNormal'; |
20 | 20 | $len = strlen($text); |
21 | - if($len == 0){ |
|
21 | + if ($len == 0) { |
|
22 | 22 | return; |
23 | 23 | } |
24 | - while (true){ |
|
25 | - if($state == 'stateNormal' && count($this->rawParams)+1 == $limit){ |
|
24 | + while (true) { |
|
25 | + if ($state == 'stateNormal' && count($this->rawParams) + 1 == $limit) { |
|
26 | 26 | break; |
27 | 27 | } |
28 | 28 | $pos = $this->$state($text, $pos, $state); |
29 | - if($pos === false || $pos>= $len){ |
|
29 | + if ($pos === false || $pos>=$len) { |
|
30 | 30 | break; |
31 | 31 | } |
32 | 32 | }; |
33 | - if($this->prePos != strlen($text)){ |
|
34 | - $this->rawParams[] = substr($text,$this->prePos); |
|
33 | + if ($this->prePos != strlen($text)) { |
|
34 | + $this->rawParams[] = substr($text, $this->prePos); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -42,16 +42,16 @@ discard block |
||
42 | 42 | { |
43 | 43 | //查找引号或者空格 |
44 | 44 | $found = []; |
45 | - $todo = substr($text,$pos); |
|
46 | - if(!preg_match('/[\s"\']/', $todo, $found, PREG_OFFSET_CAPTURE) || |
|
47 | - count($found)==0){ |
|
48 | - $this->rawParams[] = substr($text,$this->prePos); |
|
45 | + $todo = substr($text, $pos); |
|
46 | + if (!preg_match('/[\s"\']/', $todo, $found, PREG_OFFSET_CAPTURE) || |
|
47 | + count($found) == 0) { |
|
48 | + $this->rawParams[] = substr($text, $this->prePos); |
|
49 | 49 | $this->prePos = strlen($text); |
50 | 50 | return false; |
51 | 51 | } |
52 | 52 | list($chars, $offset) = $found[0]; |
53 | 53 | |
54 | - if($chars == '"'){ |
|
54 | + if ($chars == '"') { |
|
55 | 55 | $next = 'stateDoubleQ'; |
56 | 56 | return $pos + $offset + 1; |
57 | 57 | } |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | // $next = 'stateSingleQ'; |
60 | 60 | // return $pos + $offset + 1; |
61 | 61 | // } |
62 | - else{ |
|
63 | - $this->rawParams[] = substr($text,$this->prePos, $pos-$this->prePos+$offset); |
|
62 | + else { |
|
63 | + $this->rawParams[] = substr($text, $this->prePos, $pos - $this->prePos + $offset); |
|
64 | 64 | $next = 'stateSpace'; |
65 | 65 | $this->prePos = $pos + $offset + 1; |
66 | 66 | return $this->prePos; |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | private function stateSpace($text, $pos, &$next) |
74 | 74 | { |
75 | 75 | $found = []; |
76 | - $todo = substr($text,$pos); |
|
77 | - if(!preg_match('/\S/', $todo, $found, PREG_OFFSET_CAPTURE) || |
|
78 | - count($found)==0){ |
|
76 | + $todo = substr($text, $pos); |
|
77 | + if (!preg_match('/\S/', $todo, $found, PREG_OFFSET_CAPTURE) || |
|
78 | + count($found) == 0) { |
|
79 | 79 | return false; |
80 | 80 | } |
81 | 81 | list($chars, $offset) = $found[0]; |
@@ -105,20 +105,20 @@ discard block |
||
105 | 105 | /** |
106 | 106 | * 进入双引号状态 |
107 | 107 | */ |
108 | - private function stateDoubleQ($text, $pos, &$next){ |
|
108 | + private function stateDoubleQ($text, $pos, &$next) { |
|
109 | 109 | |
110 | 110 | $found = []; |
111 | - $todo = substr($text,$pos); |
|
112 | - if(!preg_match('/[\\\\"]/', $todo, $found, PREG_OFFSET_CAPTURE) || |
|
113 | - count($found)==0){ |
|
111 | + $todo = substr($text, $pos); |
|
112 | + if (!preg_match('/[\\\\"]/', $todo, $found, PREG_OFFSET_CAPTURE) || |
|
113 | + count($found) == 0) { |
|
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | list($chars, $offset) = $found[0]; |
117 | - if($chars == '\\'){ |
|
118 | - return $pos+$offset+2; |
|
119 | - }else{ |
|
117 | + if ($chars == '\\') { |
|
118 | + return $pos + $offset + 2; |
|
119 | + }else { |
|
120 | 120 | $next = 'stateNormal'; |
121 | - return $pos+$offset+1; |
|
121 | + return $pos + $offset + 1; |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
@@ -127,38 +127,38 @@ discard block |
||
127 | 127 | return count($this->rawParams); |
128 | 128 | } |
129 | 129 | |
130 | - public function getParam($pos, $default = null, $ignoreError=false) |
|
130 | + public function getParam($pos, $default = null, $ignoreError = false) |
|
131 | 131 | { |
132 | - if(isset($this->cachedParams[$pos])){ |
|
132 | + if (isset($this->cachedParams[$pos])) { |
|
133 | 133 | return $this->cachedParams[$pos]; |
134 | 134 | } |
135 | - if(isset($this->rawParams[$pos])){ |
|
135 | + if (isset($this->rawParams[$pos])) { |
|
136 | 136 | $param = $this->rawParams[$pos]; |
137 | 137 | $param = $this->stripSlashes($param, $ignoreError); |
138 | 138 | $this->cachedParams[$pos] = $param; |
139 | 139 | return $param; |
140 | - }else{ |
|
140 | + }else { |
|
141 | 141 | return $default; |
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | 145 | public function getRawParam($pos, $default = null) |
146 | 146 | { |
147 | - if(isset($this->rawParams[$pos])){ |
|
147 | + if (isset($this->rawParams[$pos])) { |
|
148 | 148 | return $this->rawParams[$pos]; |
149 | - }else{ |
|
149 | + }else { |
|
150 | 150 | return $default; |
151 | 151 | } |
152 | 152 | } |
153 | 153 | |
154 | 154 | private function stripSlashes($text, $ignoreError) |
155 | 155 | { |
156 | - if(strlen($text)>=2 && substr($text,0,1) == '"'){ |
|
156 | + if (strlen($text)>=2 && substr($text, 0, 1) == '"') { |
|
157 | 157 | $decoded = json_decode($text); |
158 | - if(json_last_error()){ |
|
159 | - if($ignoreError){ |
|
158 | + if (json_last_error()) { |
|
159 | + if ($ignoreError) { |
|
160 | 160 | return $text; |
161 | - }else{ |
|
161 | + }else { |
|
162 | 162 | \PhpBoot\abort('json_decode failed with '.json_last_error_msg(), [$text]); |
163 | 163 | } |
164 | 164 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | list($chars, $offset) = $found[0]; |
117 | 117 | if($chars == '\\'){ |
118 | 118 | return $pos+$offset+2; |
119 | - }else{ |
|
119 | + } else{ |
|
120 | 120 | $next = 'stateNormal'; |
121 | 121 | return $pos+$offset+1; |
122 | 122 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $param = $this->stripSlashes($param, $ignoreError); |
138 | 138 | $this->cachedParams[$pos] = $param; |
139 | 139 | return $param; |
140 | - }else{ |
|
140 | + } else{ |
|
141 | 141 | return $default; |
142 | 142 | } |
143 | 143 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | { |
147 | 147 | if(isset($this->rawParams[$pos])){ |
148 | 148 | return $this->rawParams[$pos]; |
149 | - }else{ |
|
149 | + } else{ |
|
150 | 150 | return $default; |
151 | 151 | } |
152 | 152 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | if(json_last_error()){ |
159 | 159 | if($ignoreError){ |
160 | 160 | return $text; |
161 | - }else{ |
|
161 | + } else{ |
|
162 | 162 | \PhpBoot\abort('json_decode failed with '.json_last_error_msg(), [$text]); |
163 | 163 | } |
164 | 164 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | /** |
13 | 13 | * 写入文件 |
14 | 14 | * @param string $path 路径 |
15 | - * @param mixed $data 写入的值 |
|
15 | + * @param string $data 写入的值 |
|
16 | 16 | * @param boolean $overwrite 是否覆盖已有文件 |
17 | 17 | * @return boolean |
18 | 18 | */ |
@@ -16,15 +16,15 @@ |
||
16 | 16 | * @param boolean $overwrite 是否覆盖已有文件 |
17 | 17 | * @return boolean |
18 | 18 | */ |
19 | - static public function write($path, $data, $overwrite = true){ |
|
19 | + static public function write($path, $data, $overwrite = true) { |
|
20 | 20 | $path = str_replace('\\', '/', $path); |
21 | 21 | $fileDir = dirname($path); |
22 | 22 | $tmpFile = tempnam($fileDir); |
23 | 23 | false !== @file_put_contents($tmpFile, $data) or \PhpBoot\abort("write to file: $tmpFile failed"); |
24 | - if($overwrite){ |
|
24 | + if ($overwrite) { |
|
25 | 25 | @unlink($path); //删除原始文件 |
26 | 26 | } |
27 | - if(!@rename($tmpFile, $path)){ |
|
27 | + if (!@rename($tmpFile, $path)) { |
|
28 | 28 | @unlink($tmpFile); //删除原始文件 |
29 | 29 | \PhpBoot\abort("write to file: $tmpFile failed"); |
30 | 30 | return false; |
@@ -49,7 +49,7 @@ |
||
49 | 49 | |
50 | 50 | /** |
51 | 51 | * 获取数组的类型 |
52 | - * @param $type |
|
52 | + * @param string|null $type |
|
53 | 53 | * @return string|null |
54 | 54 | */ |
55 | 55 | static function getArrayType($type){ |
@@ -14,10 +14,10 @@ discard block |
||
14 | 14 | * @param string $type 需要标准化的字符串 |
15 | 15 | * @param string $contextClass 当前上下文所在的类,一般传__CLASS__, 用于扫描当前文件的use信息, 以便拼上namespace |
16 | 16 | */ |
17 | - static function normalize($type, $contextClass=null){ |
|
17 | + static function normalize($type, $contextClass = null) { |
|
18 | 18 | $resolver = new TypeResolver(); |
19 | 19 | $context = null; |
20 | - if($contextClass){ |
|
20 | + if ($contextClass) { |
|
21 | 21 | //TODO 优化性能 |
22 | 22 | $contextFactory = new ContextFactory(); |
23 | 23 | $context = $contextFactory->createFromReflector(new \ReflectionClass($contextClass)); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * 是否是基本类型 |
31 | 31 | * @param string $type |
32 | 32 | */ |
33 | - static function isScalarType($type){ |
|
33 | + static function isScalarType($type) { |
|
34 | 34 | return in_array($type, [ |
35 | 35 | 'bool', |
36 | 36 | 'int', |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param $type |
44 | 44 | * @return bool |
45 | 45 | */ |
46 | - static function isArray($type){ |
|
46 | + static function isArray($type) { |
|
47 | 47 | return ($type == 'array' || substr($type, -2) == '[]'); |
48 | 48 | } |
49 | 49 | |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | * @param $type |
53 | 53 | * @return string|null |
54 | 54 | */ |
55 | - static function getArrayType($type){ |
|
55 | + static function getArrayType($type) { |
|
56 | 56 | self::isArray($type) or \PhpBoot\abort(new \InvalidArgumentException("$type is not array")); |
57 | - if($type == 'array') { |
|
57 | + if ($type == 'array') { |
|
58 | 58 | return 'mixed'; |
59 | - }else{ |
|
60 | - return substr($type,0,-2); |
|
59 | + }else { |
|
60 | + return substr($type, 0, -2); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | } |
64 | 64 | \ No newline at end of file |
@@ -56,7 +56,7 @@ |
||
56 | 56 | self::isArray($type) or \PhpBoot\abort(new \InvalidArgumentException("$type is not array")); |
57 | 57 | if($type == 'array') { |
58 | 58 | return 'mixed'; |
59 | - }else{ |
|
59 | + } else{ |
|
60 | 60 | return substr($type,0,-2); |
61 | 61 | } |
62 | 62 | } |
@@ -10,10 +10,10 @@ |
||
10 | 10 | { |
11 | 11 | $path = sys_get_temp_dir().'/lock_252a8fdc9b944af99a9bc53d2aea08f1/'.$key; |
12 | 12 | $tmpFile = tempnam($path, 'lock'); |
13 | - if(SafeFileWriter::write($tmpFile, json_encode(['time'=>time(), 'ttl'=>$ttl]), false)){ |
|
13 | + if (SafeFileWriter::write($tmpFile, json_encode(['time'=>time(), 'ttl'=>$ttl]), false)) { |
|
14 | 14 | $this->locked = true; |
15 | 15 | return true; |
16 | - }else{ |
|
16 | + }else { |
|
17 | 17 | return false; |
18 | 18 | } |
19 | 19 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | if(SafeFileWriter::write($tmpFile, json_encode(['time'=>time(), 'ttl'=>$ttl]), false)){ |
14 | 14 | $this->locked = true; |
15 | 15 | return true; |
16 | - }else{ |
|
16 | + } else{ |
|
17 | 17 | return false; |
18 | 18 | } |
19 | 19 | } |
@@ -8,20 +8,20 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class LocalAutoLock |
10 | 10 | { |
11 | - static function lock($key, $seconds, callable $success, callable $error=null){ |
|
11 | + static function lock($key, $seconds, callable $success, callable $error = null) { |
|
12 | 12 | $key = 'lock:'.$key; |
13 | - if(function_exists('apc_add')){ |
|
13 | + if (function_exists('apc_add')) { |
|
14 | 14 | $lock = new ApcLock(); |
15 | - }else{ |
|
15 | + }else { |
|
16 | 16 | $lock = new FileLock(); |
17 | 17 | } |
18 | - try{ |
|
19 | - if(!isset(self::$currentLock[$key])){ |
|
18 | + try { |
|
19 | + if (!isset(self::$currentLock[$key])) { |
|
20 | 20 | self::$currentLock[$key] = 0; |
21 | 21 | } |
22 | - if(self::$currentLock[$key] == 0){ //未加锁 |
|
23 | - if(!$lock->lock($key, $seconds)){ //加锁失败 |
|
24 | - if($error){ |
|
22 | + if (self::$currentLock[$key] == 0) { //未加锁 |
|
23 | + if (!$lock->lock($key, $seconds)) { //加锁失败 |
|
24 | + if ($error) { |
|
25 | 25 | return $error(); |
26 | 26 | } |
27 | 27 | return; |
@@ -29,34 +29,34 @@ discard block |
||
29 | 29 | } |
30 | 30 | //嵌套加锁 |
31 | 31 | self::$currentLock[$key]++; |
32 | - }catch (\Exception $e){ |
|
32 | + }catch (\Exception $e) { |
|
33 | 33 | return $error($e); |
34 | 34 | } |
35 | 35 | $res = null; |
36 | - try{ |
|
36 | + try { |
|
37 | 37 | $res = $success(); |
38 | - }catch (\Exception $e){ |
|
38 | + }catch (\Exception $e) { |
|
39 | 39 | self::$currentLock[$key]--; |
40 | - if(self::$currentLock[$key] == 0){ |
|
41 | - try{ |
|
40 | + if (self::$currentLock[$key] == 0) { |
|
41 | + try { |
|
42 | 42 | $lock->unlock($key); |
43 | - }catch (\Exception $e){ |
|
43 | + }catch (\Exception $e) { |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | } |
47 | 47 | throw $e; |
48 | 48 | } |
49 | 49 | self::$currentLock[$key]--; |
50 | - if(self::$currentLock[$key] == 0){ |
|
51 | - try{ |
|
50 | + if (self::$currentLock[$key] == 0) { |
|
51 | + try { |
|
52 | 52 | $lock->unlock($key); |
53 | - }catch (\Exception $e){ |
|
53 | + }catch (\Exception $e) { |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | } |
57 | 57 | return $res; |
58 | 58 | } |
59 | 59 | |
60 | - private $cache=[]; |
|
61 | - static private $currentLock=[]; |
|
60 | + private $cache = []; |
|
61 | + static private $currentLock = []; |
|
62 | 62 | } |
63 | 63 | \ No newline at end of file |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | $key = 'lock:'.$key; |
13 | 13 | if(function_exists('apc_add')){ |
14 | 14 | $lock = new ApcLock(); |
15 | - }else{ |
|
15 | + } else{ |
|
16 | 16 | $lock = new FileLock(); |
17 | 17 | } |
18 | 18 | try{ |
@@ -29,18 +29,18 @@ discard block |
||
29 | 29 | } |
30 | 30 | //嵌套加锁 |
31 | 31 | self::$currentLock[$key]++; |
32 | - }catch (\Exception $e){ |
|
32 | + } catch (\Exception $e){ |
|
33 | 33 | return $error($e); |
34 | 34 | } |
35 | 35 | $res = null; |
36 | 36 | try{ |
37 | 37 | $res = $success(); |
38 | - }catch (\Exception $e){ |
|
38 | + } catch (\Exception $e){ |
|
39 | 39 | self::$currentLock[$key]--; |
40 | 40 | if(self::$currentLock[$key] == 0){ |
41 | 41 | try{ |
42 | 42 | $lock->unlock($key); |
43 | - }catch (\Exception $e){ |
|
43 | + } catch (\Exception $e){ |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | if(self::$currentLock[$key] == 0){ |
51 | 51 | try{ |
52 | 52 | $lock->unlock($key); |
53 | - }catch (\Exception $e){ |
|
53 | + } catch (\Exception $e){ |
|
54 | 54 | |
55 | 55 | } |
56 | 56 | } |
@@ -6,10 +6,10 @@ discard block |
||
6 | 6 | |
7 | 7 | public function lock($key, $ttl) |
8 | 8 | { |
9 | - if(apc_add($key, 1, $ttl)){ |
|
9 | + if (apc_add($key, 1, $ttl)) { |
|
10 | 10 | $this->locked = true; |
11 | 11 | return true; |
12 | - }else{ |
|
12 | + }else { |
|
13 | 13 | return false; |
14 | 14 | } |
15 | 15 | } |
@@ -21,5 +21,5 @@ discard block |
||
21 | 21 | $this->locked = false; |
22 | 22 | return $res; |
23 | 23 | } |
24 | - private $locked=false; |
|
24 | + private $locked = false; |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -9,7 +9,7 @@ |
||
9 | 9 | if(apc_add($key, 1, $ttl)){ |
10 | 10 | $this->locked = true; |
11 | 11 | return true; |
12 | - }else{ |
|
12 | + } else{ |
|
13 | 13 | return false; |
14 | 14 | } |
15 | 15 | } |