@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $op->description = $route->getDescription(); |
| 59 | 59 | |
| 60 | 60 | $op->parameters = $this->getParamsSchema($app, $controller, $action, $route); |
| 61 | - if($this->hasFileParam($route)){ |
|
| 61 | + if ($this->hasFileParam($route)) { |
|
| 62 | 62 | $op->consumes = ['multipart/form-data']; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | if (is_array($v) || is_object($v)) { |
| 110 | 110 | $res[$k] = self::objectToArray($v); |
| 111 | - } else { |
|
| 111 | + }else { |
|
| 112 | 112 | $res[$k] = $v; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -136,12 +136,12 @@ discard block |
||
| 136 | 136 | list($name, $desc) = $exception; |
| 137 | 137 | |
| 138 | 138 | $ins = null; |
| 139 | - try{ |
|
| 139 | + try { |
|
| 140 | 140 | $ins = $app->make($name); |
| 141 | - }catch (\Exception $e){ |
|
| 142 | - try{ |
|
| 141 | + }catch (\Exception $e) { |
|
| 142 | + try { |
|
| 143 | 143 | $ins = new $name(""); |
| 144 | - }catch (\Exception $e){ |
|
| 144 | + }catch (\Exception $e) { |
|
| 145 | 145 | |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -149,21 +149,21 @@ discard block |
||
| 149 | 149 | //TODO status 重复怎么办 |
| 150 | 150 | if ($ins instanceof HttpException) { |
| 151 | 151 | $status = $ins->getStatusCode(); |
| 152 | - } else { |
|
| 152 | + }else { |
|
| 153 | 153 | $status = 500; |
| 154 | 154 | } |
| 155 | 155 | if (isset($schemas[$status])) { |
| 156 | 156 | //$this->warnings[] = "status response $status has been used for $name, $desc"; |
| 157 | 157 | $res = $schemas[$status]; |
| 158 | - } else { |
|
| 158 | + }else { |
|
| 159 | 159 | $res = new ResponseObject(); |
| 160 | 160 | } |
| 161 | 161 | $shortName = self::getShortClassName($name); |
| 162 | 162 | $desc = "$shortName: $desc"; |
| 163 | 163 | $res->description = self::implode("\n", [$res->description, $desc]); |
| 164 | - if($ins){ |
|
| 164 | + if ($ins) { |
|
| 165 | 165 | $error = $app->get(ExceptionRenderer::class)->render($ins)->getContent(); |
| 166 | - if($error){ |
|
| 166 | + if ($error) { |
|
| 167 | 167 | $res->examples = [$shortName => $error]; |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -223,9 +223,9 @@ discard block |
||
| 223 | 223 | { |
| 224 | 224 | if ($content instanceof ReturnMeta || $content instanceof ParamMeta) { |
| 225 | 225 | return $this->makeExample($content->container); |
| 226 | - }elseif ($content instanceof TypeContainerInterface){ |
|
| 226 | + }elseif ($content instanceof TypeContainerInterface) { |
|
| 227 | 227 | return $content->makeExample(); |
| 228 | - }elseif(is_array($content)) { |
|
| 228 | + }elseif (is_array($content)) { |
|
| 229 | 229 | $res = []; |
| 230 | 230 | foreach ($content as $k => $v) { |
| 231 | 231 | $res[$k] = $this->makeExample($v); |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | array $arr, $suffix) |
| 251 | 251 | { |
| 252 | 252 | $className = self::getShortClassName($controller->getClassName()); |
| 253 | - $name = $className . ucfirst($action) . $suffix; |
|
| 253 | + $name = $className.ucfirst($action).$suffix; |
|
| 254 | 254 | |
| 255 | 255 | $schema = new SimpleModelSchemaObject(); |
| 256 | 256 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | $schema->properties[$k] = $this->makeTempSchema($app, $controller, $action, $route, $v, $suffix); |
| 260 | 260 | } elseif ($v instanceof ReturnMeta) { |
| 261 | 261 | $sub = $this->getAnySchema($app, $controller, $action, $route, $v->container); |
| 262 | - if($sub){ |
|
| 262 | + if ($sub) { |
|
| 263 | 263 | $sub->description = $v->description; |
| 264 | 264 | } |
| 265 | 265 | $schema->properties[$k] = $sub; |
@@ -270,13 +270,13 @@ discard block |
||
| 270 | 270 | } elseif ($v->container instanceof EntityContainer) { |
| 271 | 271 | $sub = $this->getRefSchema($app, $controller, $action, $route, $v->container); |
| 272 | 272 | //TODO array for validation |
| 273 | - } else { |
|
| 273 | + }else { |
|
| 274 | 274 | $sub = new PrimitiveSchemaObject(); |
| 275 | 275 | $sub->type = self::mapType($v->type); |
| 276 | 276 | self::mapValidation($v->validation, $sub); |
| 277 | 277 | unset($sub->required); |
| 278 | 278 | } |
| 279 | - if($sub){ |
|
| 279 | + if ($sub) { |
|
| 280 | 280 | $sub->description = $v->description; |
| 281 | 281 | $sub->default = $v->default; |
| 282 | 282 | } |
@@ -284,14 +284,14 @@ discard block |
||
| 284 | 284 | $schema->required[] = $k; |
| 285 | 285 | } |
| 286 | 286 | $schema->properties[$k] = $sub; |
| 287 | - } else { |
|
| 287 | + }else { |
|
| 288 | 288 | //TODO how to do? |
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | $unused = $name; |
| 292 | 292 | $tempId = 0; |
| 293 | 293 | while (isset($this->definitions[$unused])) { |
| 294 | - $unused = $name . $tempId; |
|
| 294 | + $unused = $name.$tempId; |
|
| 295 | 295 | $tempId++; |
| 296 | 296 | } |
| 297 | 297 | $this->definitions[$unused] = $schema; |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $in = 'query'; |
| 331 | 331 | |
| 332 | 332 | $bodyType = 'body'; // 当有文件上传时, 必须是formData方式 |
| 333 | - if($this->hasFileParam($route)){ |
|
| 333 | + if ($this->hasFileParam($route)) { |
|
| 334 | 334 | $bodyType = 'formData'; |
| 335 | 335 | } |
| 336 | 336 | |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | || $route->getMethod() == 'PATCH' |
| 370 | 370 | ) { |
| 371 | 371 | $in = $bodyType; |
| 372 | - } else { |
|
| 372 | + }else { |
|
| 373 | 373 | $in = 'query'; |
| 374 | 374 | } |
| 375 | 375 | } |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | } elseif ($param->container instanceof EntityContainer) { |
| 381 | 381 | $paramSchema = $this->getRefSchema($app, $controller, $action, $route, $param->container); |
| 382 | 382 | //TODO array for validation |
| 383 | - } else { |
|
| 383 | + }else { |
|
| 384 | 384 | $paramSchema = new PrimitiveSchemaObject(); |
| 385 | - if($isFile){ |
|
| 385 | + if ($isFile) { |
|
| 386 | 386 | $paramSchema->type = 'file'; |
| 387 | - }else{ |
|
| 387 | + }else { |
|
| 388 | 388 | $paramSchema->type = self::mapType($param->type); |
| 389 | 389 | self::mapValidation($param->validation, $paramSchema); |
| 390 | 390 | } |
@@ -396,10 +396,10 @@ discard block |
||
| 396 | 396 | $paramSchema->default = $param->default; |
| 397 | 397 | $paramSchema->required = !$param->isOptional; |
| 398 | 398 | $parameters[] = $paramSchema; |
| 399 | - } else { |
|
| 399 | + }else { |
|
| 400 | 400 | if (!$name) { |
| 401 | 401 | $body = $param; |
| 402 | - } else { |
|
| 402 | + }else { |
|
| 403 | 403 | ArrayHelper::set($body, $name, $param); |
| 404 | 404 | } |
| 405 | 405 | |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | $paramSchema->in = 'body'; |
| 413 | 413 | if (is_array($body)) { |
| 414 | 414 | $paramSchema->schema = $this->makeTempSchema($app, $controller, $action, $route, $body, 'Req'); |
| 415 | - } else { |
|
| 415 | + }else { |
|
| 416 | 416 | $paramSchema->schema = $this->getAnySchema($app, $controller, $action, $route, $body->container); |
| 417 | 417 | } |
| 418 | 418 | |
@@ -439,8 +439,8 @@ discard block |
||
| 439 | 439 | } elseif ($container instanceof ScalarTypeContainer) { |
| 440 | 440 | $schema = new PrimitiveSchemaObject(); |
| 441 | 441 | $schema->type = self::mapType($container->getType()); |
| 442 | - } elseif($container == null){ |
|
| 443 | - $schema = null ;//new PrimitiveSchemaObject(); |
|
| 442 | + } elseif ($container == null) { |
|
| 443 | + $schema = null; //new PrimitiveSchemaObject(); |
|
| 444 | 444 | //$schema->type = null; |
| 445 | 445 | }else { |
| 446 | 446 | $schema = new PrimitiveSchemaObject(); |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | } elseif ($itemContainer instanceof ScalarTypeContainer) { |
| 473 | 473 | $itemSchema = new PrimitiveSchemaObject(); |
| 474 | 474 | $itemSchema->type = self::mapType($itemContainer->getType()); |
| 475 | - } else { |
|
| 475 | + }else { |
|
| 476 | 476 | $itemSchema = new PrimitiveSchemaObject(); |
| 477 | 477 | //$itemSchema->type = 'mixed'; |
| 478 | 478 | } |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | $propertySchema = $this->getRefSchema($app, $controller, $action, $route, $property->container); |
| 499 | 499 | } elseif ($property->container instanceof ArrayContainer) { |
| 500 | 500 | $propertySchema = $this->getArraySchema($app, $controller, $action, $route, $property->container); |
| 501 | - } else { |
|
| 501 | + }else { |
|
| 502 | 502 | $propertySchema = new PrimitiveSchemaObject(); |
| 503 | 503 | $propertySchema->type = self::mapType($property->type); |
| 504 | 504 | $propertySchema->description = self::implode("\n", [$property->summary, $property->description]); |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | { |
| 516 | 516 | $params = $route->getRequestHandler()->getParamMetas(); |
| 517 | 517 | foreach ($params as $name => $param) { |
| 518 | - if(strpos($param->source, 'request.files.')===0){ |
|
| 518 | + if (strpos($param->source, 'request.files.') === 0) { |
|
| 519 | 519 | return true; |
| 520 | 520 | } |
| 521 | 521 | } |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | */ |
| 529 | 529 | static public function mapValidation($v, PrimitiveSchemaObject $schemaObject) |
| 530 | 530 | { |
| 531 | - if(!$v){ |
|
| 531 | + if (!$v) { |
|
| 532 | 532 | return $schemaObject; |
| 533 | 533 | } |
| 534 | 534 | $rules = explode('|', $v); |
@@ -544,15 +544,15 @@ discard block |
||
| 544 | 544 | } elseif ($rule == 'lengthBetween' && isset($params[0]) && isset($params[1])) { |
| 545 | 545 | $schemaObject->minLength = intval($params[0]); |
| 546 | 546 | $schemaObject->maxLength = intval($params[1]); |
| 547 | - } elseif ($rule == 'lengthMin'&& isset($params[0])) { |
|
| 547 | + } elseif ($rule == 'lengthMin' && isset($params[0])) { |
|
| 548 | 548 | $schemaObject->minLength = intval($params[0]); |
| 549 | - } elseif ($rule == 'lengthMax'&& isset($params[0])) { |
|
| 549 | + } elseif ($rule == 'lengthMax' && isset($params[0])) { |
|
| 550 | 550 | $schemaObject->maxLength = intval($params[0]); |
| 551 | - } elseif ($rule == 'min'&& isset($params[0])) { |
|
| 551 | + } elseif ($rule == 'min' && isset($params[0])) { |
|
| 552 | 552 | $schemaObject->minimum = floatval($params[0]); |
| 553 | - } elseif ($rule == 'max'&& isset($params[0])) { |
|
| 553 | + } elseif ($rule == 'max' && isset($params[0])) { |
|
| 554 | 554 | $schemaObject->maximum = floatval($params[0]); |
| 555 | - } elseif ($rule == 'regex'&& isset($params[0])) { |
|
| 555 | + } elseif ($rule == 'regex' && isset($params[0])) { |
|
| 556 | 556 | $schemaObject->pattern = $params[0]; |
| 557 | 557 | } elseif ($rule == 'optional') { |
| 558 | 558 | $schemaObject->required = false; |
@@ -591,9 +591,9 @@ discard block |
||
| 591 | 591 | return $className; |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - static public function implode($glue , array $pieces ) |
|
| 594 | + static public function implode($glue, array $pieces) |
|
| 595 | 595 | { |
| 596 | - $pieces = array_filter($pieces, function($i){return trim($i) !== '';}); |
|
| 596 | + $pieces = array_filter($pieces, function($i) {return trim($i) !== ''; }); |
|
| 597 | 597 | return implode($glue, $pieces); |
| 598 | 598 | } |
| 599 | 599 | } |
| 600 | 600 | \ No newline at end of file |
@@ -41,22 +41,22 @@ discard block |
||
| 41 | 41 | //TODO【重要】 使用全局的缓存版本号, 而不是针对每个文件判断缓存过期与否 |
| 42 | 42 | $rfl = new \ReflectionClass($className) or \PhpBoot\abort("load class $className failed"); |
| 43 | 43 | $fileName = $rfl->getFileName(); |
| 44 | - $key = str_replace('\\','.',get_class($this)).md5(serialize($this->annotations).$fileName.$className); |
|
| 44 | + $key = str_replace('\\', '.', get_class($this)).md5(serialize($this->annotations).$fileName.$className); |
|
| 45 | 45 | $cache = new CheckableCache($this->cache); |
| 46 | 46 | $res = $cache->get($key, $this); |
| 47 | - if($res === $this){ |
|
| 48 | - try{ |
|
| 47 | + if ($res === $this) { |
|
| 48 | + try { |
|
| 49 | 49 | $meta = $this->buildWithoutCache($className); |
| 50 | - $cache->set($key, $meta, 0, $fileName?new ClassModifiedChecker($className):null); |
|
| 50 | + $cache->set($key, $meta, 0, $fileName ? new ClassModifiedChecker($className) : null); |
|
| 51 | 51 | return $meta; |
| 52 | - }catch (\Exception $e){ |
|
| 52 | + }catch (\Exception $e) { |
|
| 53 | 53 | Logger::warning(__METHOD__.' failed with '.$e->getMessage()); |
| 54 | - $cache->set($key, $e->getMessage(), 0, $fileName?new ClassModifiedChecker($className):null); |
|
| 54 | + $cache->set($key, $e->getMessage(), 0, $fileName ? new ClassModifiedChecker($className) : null); |
|
| 55 | 55 | throw $e; |
| 56 | 56 | } |
| 57 | - }elseif(is_string($res)){ |
|
| 57 | + }elseif (is_string($res)) { |
|
| 58 | 58 | \PhpBoot\abort($res); |
| 59 | - }else{ |
|
| 59 | + }else { |
|
| 60 | 60 | return $res; |
| 61 | 61 | } |
| 62 | 62 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | |
| 73 | 73 | } |
| 74 | - protected function handleAnnotation($handlerName, $container, $ann){ |
|
| 74 | + protected function handleAnnotation($handlerName, $container, $ann) { |
|
| 75 | 75 | $handler = new $handlerName(); |
| 76 | 76 | return $handler($container, $ann); |
| 77 | 77 | } |
@@ -83,15 +83,15 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | $container = $this->createContainer($className); |
| 85 | 85 | $anns = AnnotationReader::read($className, $this->cache); |
| 86 | - foreach ($this->annotations as $i){ |
|
| 86 | + foreach ($this->annotations as $i) { |
|
| 87 | 87 | list($class, $target) = $i; |
| 88 | 88 | |
| 89 | 89 | $found = \JmesPath\search($target, $anns); |
| 90 | - if(is_array($found)){ |
|
| 91 | - foreach ($found as $f){ |
|
| 92 | - $this->handleAnnotation($class, $container,$f); //TODO 支持 |
|
| 90 | + if (is_array($found)) { |
|
| 91 | + foreach ($found as $f) { |
|
| 92 | + $this->handleAnnotation($class, $container, $f); //TODO 支持 |
|
| 93 | 93 | } |
| 94 | - }else{ |
|
| 94 | + }else { |
|
| 95 | 95 | $this->handleAnnotation($class, $container, $found); |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | /** |
| 103 | 103 | * @var array |
| 104 | 104 | */ |
| 105 | - private $annotations=[]; |
|
| 105 | + private $annotations = []; |
|
| 106 | 106 | /** |
| 107 | 107 | * @var Cache |
| 108 | 108 | */ |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | class ConsoleContainerBuilder extends ContainerBuilder |
| 23 | 23 | { |
| 24 | - static $DEFAULT_ANNOTATIONS=[ |
|
| 24 | + static $DEFAULT_ANNOTATIONS = [ |
|
| 25 | 25 | [ClassAnnotationHandler::class, 'class'], |
| 26 | 26 | [CommandNameAnnotationHandler::class, "class.children[?name=='command']"], |
| 27 | 27 | [CommandAnnotationHandler::class, "methods.*.children[?name=='command'][]"], |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | array $annotations = null |
| 44 | 44 | ) |
| 45 | 45 | { |
| 46 | - if($annotations){ |
|
| 46 | + if ($annotations) { |
|
| 47 | 47 | parent::__construct($annotations, $cache); |
| 48 | - }else{ |
|
| 48 | + }else { |
|
| 49 | 49 | parent::__construct(self::$DEFAULT_ANNOTATIONS, $cache); |
| 50 | 50 | } |
| 51 | 51 | $this->factory = $factory; |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | $name = $params->getParam(0, $target); |
| 26 | 26 | |
| 27 | 27 | //获取方法参数信息 |
| 28 | - $rfl = new \ReflectionClass($container->getClassName()); |
|
| 28 | + $rfl = new \ReflectionClass($container->getClassName()); |
|
| 29 | 29 | $method = $rfl->getMethod($target); |
| 30 | 30 | $methodParams = $method->getParameters(); |
| 31 | 31 | |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | //设置参数列表 |
| 37 | 37 | $paramsMeta = []; |
| 38 | - foreach ($methodParams as $param){ |
|
| 38 | + foreach ($methodParams as $param) { |
|
| 39 | 39 | $paramName = $param->getName(); |
| 40 | 40 | $source = "argv.$paramName"; |
| 41 | 41 | $paramClass = $param->getClass(); |
| 42 | - if($paramClass){ |
|
| 42 | + if ($paramClass) { |
|
| 43 | 43 | $paramClass = $paramClass->getName(); |
| 44 | 44 | } |
| 45 | 45 | $entityContainer = ContainerFactory::create($entityBuilder, $paramClass); |
| 46 | 46 | $meta = new ParamMeta($paramName, |
| 47 | 47 | $source, |
| 48 | - $paramClass?:'mixed', |
|
| 48 | + $paramClass ?: 'mixed', |
|
| 49 | 49 | $param->isOptional(), |
| 50 | - $param->isOptional()?$param->getDefaultValue():null, |
|
| 50 | + $param->isOptional() ? $param->getDefaultValue() : null, |
|
| 51 | 51 | $param->isPassedByReference(), |
| 52 | 52 | null, |
| 53 | 53 | '', |
@@ -22,17 +22,17 @@ discard block |
||
| 22 | 22 | $paramType = null; |
| 23 | 23 | $paramName = null; |
| 24 | 24 | $paramDoc = ''; |
| 25 | - if(substr($text, 0, 1) == '$'){ //带$前缀的是变量 |
|
| 25 | + if (substr($text, 0, 1) == '$') { //带$前缀的是变量 |
|
| 26 | 26 | $params = new AnnotationParams($text, 2); |
| 27 | 27 | $paramName = substr($params->getParam(0), 1); |
| 28 | 28 | $paramDoc = $params->getRawParam(1, ''); |
| 29 | - }else{ |
|
| 29 | + }else { |
|
| 30 | 30 | $params = new AnnotationParams($text, 3); |
| 31 | - if ($params->count() >=2 && substr($params->getParam(1), 0, 1) == '$'){ |
|
| 31 | + if ($params->count()>=2 && substr($params->getParam(1), 0, 1) == '$') { |
|
| 32 | 32 | $paramType = $params->getParam(0); //TODO 检测类型是否合法 |
| 33 | 33 | $paramName = substr($params->getParam(1), 1); |
| 34 | 34 | $paramDoc = $params->getRawParam(2, ''); |
| 35 | - }else{ |
|
| 35 | + }else { |
|
| 36 | 36 | \PhpBoot\abort(new AnnotationSyntaxException("@param $text syntax error")); |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -45,15 +45,15 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function __invoke(ConsoleContainer $container, $ann, EntityContainerBuilder $entityBuilder) |
| 47 | 47 | { |
| 48 | - if(!$ann->parent){ |
|
| 48 | + if (!$ann->parent) { |
|
| 49 | 49 | //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent route"); |
| 50 | 50 | return; |
| 51 | 51 | } |
| 52 | 52 | $target = $ann->parent->name; |
| 53 | 53 | $command = $container->getCommand($target); |
| 54 | - if(!$command){ |
|
| 54 | + if (!$command) { |
|
| 55 | 55 | //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent route"); |
| 56 | - return ; |
|
| 56 | + return; |
|
| 57 | 57 | } |
| 58 | 58 | $className = $container->getClassName(); |
| 59 | 59 | |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | $paramMeta = $command->getParamMeta($paramName); |
| 63 | 63 | $paramMeta or \PhpBoot\abort(new AnnotationSyntaxException("$className::$target param $paramName not exist ")); |
| 64 | 64 | //TODO 检测声明的类型和注释的类型是否匹配 |
| 65 | - if($paramType){ |
|
| 66 | - $paramMeta->type = TypeHint::normalize($paramType, $className);//or \PhpBoot\abort(new AnnotationSyntaxException("{$container->getClassName()}::{$ann->parent->name} @{$ann->name} syntax error, param $paramName unknown type:$paramType ")); |
|
| 65 | + if ($paramType) { |
|
| 66 | + $paramMeta->type = TypeHint::normalize($paramType, $className); //or \PhpBoot\abort(new AnnotationSyntaxException("{$container->getClassName()}::{$ann->parent->name} @{$ann->name} syntax error, param $paramName unknown type:$paramType ")); |
|
| 67 | 67 | $container = ContainerFactory::create($entityBuilder, $paramMeta->type); |
| 68 | 68 | $paramMeta->container = $container; |
| 69 | 69 | } |
@@ -18,29 +18,29 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | public function __invoke(ConsoleContainer $container, $ann) |
| 20 | 20 | { |
| 21 | - if(!$ann->parent || !$ann->parent->parent){ |
|
| 21 | + if (!$ann->parent || !$ann->parent->parent) { |
|
| 22 | 22 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent parent"); |
| 23 | 23 | return; |
| 24 | 24 | } |
| 25 | 25 | $target = $ann->parent->parent->name; |
| 26 | 26 | $command = $container->getCommand($target); |
| 27 | - if(!$command){ |
|
| 27 | + if (!$command) { |
|
| 28 | 28 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent parent"); |
| 29 | - return ; |
|
| 29 | + return; |
|
| 30 | 30 | } |
| 31 | 31 | $params = new AnnotationParams($ann->description, 2); |
| 32 | 32 | |
| 33 | 33 | count($params)>0 or \PhpBoot\abort(new AnnotationSyntaxException("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require 1 param, {$params->count()} given")); |
| 34 | 34 | |
| 35 | - if($ann->parent->name == 'param'){ |
|
| 35 | + if ($ann->parent->name == 'param') { |
|
| 36 | 36 | list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description); |
| 37 | 37 | |
| 38 | 38 | $paramMeta = $command->getParamMeta($paramName); |
| 39 | - if($params->count()>1){ |
|
| 39 | + if ($params->count()>1) { |
|
| 40 | 40 | $paramMeta->validation = [$params[0], $params[1]]; |
| 41 | - }else{ |
|
| 41 | + }else { |
|
| 42 | 42 | $paramMeta->validation = $params[0]; |
| 43 | - if($paramMeta->validation) { |
|
| 43 | + if ($paramMeta->validation) { |
|
| 44 | 44 | $v = new Validator(); |
| 45 | 45 | $v->rule($paramMeta->validation, $paramMeta->name); |
| 46 | 46 | if ($v->hasRule('optional', $paramMeta->name)) { |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $container = $this->consoleContainerBuilder->build($className); |
| 56 | 56 | /**@var ConsoleContainer $container*/ |
| 57 | 57 | foreach ($container->getCommands() as $name => $command) { |
| 58 | - $command->setCode(function (InputInterface $input, OutputInterface $output)use ($container, $command){ |
|
| 58 | + $command->setCode(function(InputInterface $input, OutputInterface $output)use ($container, $command){ |
|
| 59 | 59 | return $this->diInvoker->call([$command, 'invoke'], ['container'=>$container, 'input'=>$input, 'output'=>$output]); |
| 60 | 60 | }); |
| 61 | 61 | $this->add($command); |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | $dir = @dir($fromPath) or abort("dir $fromPath not exist"); |
| 73 | 73 | |
| 74 | - $getEach = function () use ($dir) { |
|
| 74 | + $getEach = function() use ($dir) { |
|
| 75 | 75 | $name = $dir->read(); |
| 76 | 76 | if (!$name) { |
| 77 | 77 | return $name; |
@@ -83,11 +83,11 @@ discard block |
||
| 83 | 83 | if ($entry == '.' || $entry == '..') { |
| 84 | 84 | continue; |
| 85 | 85 | } |
| 86 | - $path = $fromPath . '/' . str_replace('\\', '/', $entry); |
|
| 86 | + $path = $fromPath.'/'.str_replace('\\', '/', $entry); |
|
| 87 | 87 | if (is_file($path) && substr_compare($entry, '.php', strlen($entry) - 4, 4, true) == 0) { |
| 88 | - $class_name = $namespace . '\\' . substr($entry, 0, strlen($entry) - 4); |
|
| 88 | + $class_name = $namespace.'\\'.substr($entry, 0, strlen($entry) - 4); |
|
| 89 | 89 | $this->loadCommandsFromClass($class_name); |
| 90 | - } else { |
|
| 90 | + }else { |
|
| 91 | 91 | //\Log::debug($path.' ignored'); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | public function getCommand($target) |
| 60 | 60 | { |
| 61 | - return isset($this->commands[$target])?$this->commands[$target]:null; |
|
| 61 | + return isset($this->commands[$target]) ? $this->commands[$target] : null; |
|
| 62 | 62 | } |
| 63 | 63 | /** |
| 64 | 64 | * @return string |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | public function postCreate() |
| 99 | 99 | { |
| 100 | - foreach ($this->commands as $command){ |
|
| 100 | + foreach ($this->commands as $command) { |
|
| 101 | 101 | $command->postCreate($this); |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function getInstance(FactoryInterface $factory) |
| 115 | 115 | { |
| 116 | - if(!$this->instance ){ |
|
| 117 | - $this->instance = $factory->make($this->getClassName()); |
|
| 116 | + if (!$this->instance) { |
|
| 117 | + $this->instance = $factory->make($this->getClassName()); |
|
| 118 | 118 | } |
| 119 | 119 | return $this->instance; |
| 120 | 120 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function __construct($actionName, $name) |
| 37 | 37 | { |
| 38 | - parent::__construct($name?:$actionName); |
|
| 38 | + parent::__construct($name ?: $actionName); |
|
| 39 | 39 | $this->actionName = $actionName; |
| 40 | 40 | } |
| 41 | 41 | /** |
@@ -48,14 +48,14 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | public function postCreate(ConsoleContainer $container) |
| 50 | 50 | { |
| 51 | - if($container->getModuleName()){ |
|
| 51 | + if ($container->getModuleName()) { |
|
| 52 | 52 | $this->setName($container->getModuleName().'.'.$this->getName()); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - foreach ($this->paramMetas as $paramMeta){ |
|
| 56 | - $mode = $paramMeta->isOptional?InputArgument::OPTIONAL:InputArgument::REQUIRED; |
|
| 57 | - if($paramMeta->container instanceof ArrayContainer || $paramMeta->container instanceof EntityContainer){ |
|
| 58 | - $mode = $mode|InputArgument::IS_ARRAY; |
|
| 55 | + foreach ($this->paramMetas as $paramMeta) { |
|
| 56 | + $mode = $paramMeta->isOptional ?InputArgument::OPTIONAL : InputArgument::REQUIRED; |
|
| 57 | + if ($paramMeta->container instanceof ArrayContainer || $paramMeta->container instanceof EntityContainer) { |
|
| 58 | + $mode = $mode | InputArgument::IS_ARRAY; |
|
| 59 | 59 | } |
| 60 | 60 | $this->addArgument($paramMeta->name, |
| 61 | 61 | $mode, |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | public function getParamMeta($name) |
| 69 | 69 | { |
| 70 | - foreach ($this->paramMetas as $meta){ |
|
| 71 | - if($meta->name == $name){ |
|
| 70 | + foreach ($this->paramMetas as $meta) { |
|
| 71 | + if ($meta->name == $name) { |
|
| 72 | 72 | return $meta; |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -84,40 +84,40 @@ discard block |
||
| 84 | 84 | * @throws \DI\DependencyException |
| 85 | 85 | * @throws \DI\NotFoundException |
| 86 | 86 | */ |
| 87 | - public function invoke(FactoryInterface $factory,ConsoleContainer $container, InputInterface $input, OutputInterface $output) |
|
| 87 | + public function invoke(FactoryInterface $factory, ConsoleContainer $container, InputInterface $input, OutputInterface $output) |
|
| 88 | 88 | { |
| 89 | 89 | $params = []; |
| 90 | 90 | $reference = []; |
| 91 | - $this->bindInput($input, $params,$reference); |
|
| 91 | + $this->bindInput($input, $params, $reference); |
|
| 92 | 92 | $code = call_user_func_array([$container->getInstance($factory), $this->actionName], $params); |
| 93 | 93 | return $code; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - public function bindInput(InputInterface $input, array &$params, array &$reference){ |
|
| 96 | + public function bindInput(InputInterface $input, array &$params, array &$reference) { |
|
| 97 | 97 | $vld = new Validator(); |
| 98 | 98 | $req = ['argv'=>$input->getArguments()]; |
| 99 | 99 | $requestArray = new ArrayAdaptor($req); |
| 100 | 100 | $inputs = []; |
| 101 | - foreach ($this->paramMetas as $k=>$meta){ |
|
| 102 | - if($meta->isPassedByReference){ |
|
| 101 | + foreach ($this->paramMetas as $k=>$meta) { |
|
| 102 | + if ($meta->isPassedByReference) { |
|
| 103 | 103 | // param PassedByReference is used to output |
| 104 | 104 | continue; |
| 105 | 105 | } |
| 106 | 106 | $source = \JmesPath\search($meta->source, $requestArray); |
| 107 | - if ($source !== null){ |
|
| 107 | + if ($source !== null) { |
|
| 108 | 108 | $source = ArrayAdaptor::strip($source); |
| 109 | - if($source instanceof ParameterBag){ |
|
| 109 | + if ($source instanceof ParameterBag) { |
|
| 110 | 110 | $source = $source->all(); |
| 111 | 111 | } |
| 112 | - if($meta->container){ |
|
| 112 | + if ($meta->container) { |
|
| 113 | 113 | $inputs[$meta->name] = $meta->container->make($source); |
| 114 | - }else{ |
|
| 114 | + }else { |
|
| 115 | 115 | $inputs[$meta->name] = $source; |
| 116 | 116 | } |
| 117 | - if($meta->validation){ |
|
| 117 | + if ($meta->validation) { |
|
| 118 | 118 | $vld->rule($meta->validation, $meta->name); |
| 119 | 119 | } |
| 120 | - }else{ |
|
| 120 | + }else { |
|
| 121 | 121 | $meta->isOptional or \PhpBoot\abort(new \InvalidArgumentException("the parameter \"{$meta->source}\" is missing")); |
| 122 | 122 | $inputs[$meta->name] = $meta->default; |
| 123 | 123 | } |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | ); |
| 134 | 134 | |
| 135 | 135 | $pos = 0; |
| 136 | - foreach ($this->paramMetas as $meta){ |
|
| 137 | - if($meta->isPassedByReference){ |
|
| 136 | + foreach ($this->paramMetas as $meta) { |
|
| 137 | + if ($meta->isPassedByReference) { |
|
| 138 | 138 | $params[$pos] = null; |
| 139 | - }else{ |
|
| 139 | + }else { |
|
| 140 | 140 | $params[$pos] = $inputs[$meta->name]; |
| 141 | 141 | } |
| 142 | 142 | $pos++; |