@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | class EntityContainerBuilder extends ContainerBuilder |
| 15 | 15 | { |
| 16 | - static $DEFAULT_ANNOTATIONS=[ |
|
| 16 | + static $DEFAULT_ANNOTATIONS = [ |
|
| 17 | 17 | [ClassAnnotationHandler::class, 'class'], |
| 18 | 18 | [PropertyAnnotationHandler::class, 'properties'], |
| 19 | 19 | [VarAnnotationHandler::class, "properties.*.children[?name=='var'][]"], |
@@ -34,9 +34,9 @@ discard block |
||
| 34 | 34 | array $annotations = null |
| 35 | 35 | ) |
| 36 | 36 | { |
| 37 | - if($annotations){ |
|
| 37 | + if ($annotations) { |
|
| 38 | 38 | parent::__construct($annotations, $cache); |
| 39 | - }else{ |
|
| 39 | + }else { |
|
| 40 | 40 | parent::__construct(self::$DEFAULT_ANNOTATIONS, $cache); |
| 41 | 41 | } |
| 42 | 42 | $this->factory = $factory; |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | { |
| 37 | 37 | if($annotations){ |
| 38 | 38 | parent::__construct($annotations, $cache); |
| 39 | - }else{ |
|
| 39 | + } else{ |
|
| 40 | 40 | parent::__construct(self::$DEFAULT_ANNOTATIONS, $cache); |
| 41 | 41 | } |
| 42 | 42 | $this->factory = $factory; |
@@ -10,10 +10,10 @@ |
||
| 10 | 10 | public function __construct($type) |
| 11 | 11 | { |
| 12 | 12 | $this->type = $type; |
| 13 | - !$type || TypeHint::isScalarType($type) or \PhpBoot\abort(new \InvalidArgumentException("$type is not scalar type")); |
|
| 13 | + !$type || TypeHint::isScalarType($type) or \PhpBoot\abort(new \InvalidArgumentException("$type is not scalar type")); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - public function make($data, $validate = true){ |
|
| 16 | + public function make($data, $validate = true) { |
|
| 17 | 17 | return TypeCast::cast($data, $this->type, $validate); |
| 18 | 18 | } |
| 19 | 19 | |
@@ -11,17 +11,17 @@ |
||
| 11 | 11 | //TODO 支持|分隔的多类型 |
| 12 | 12 | |
| 13 | 13 | $getter = function($type)use($builder){ |
| 14 | - if(!$type || $type == 'mixed'){ |
|
| 14 | + if (!$type || $type == 'mixed') { |
|
| 15 | 15 | return new MixedTypeContainer(); |
| 16 | - }elseif (TypeHint::isScalarType($type)){ |
|
| 16 | + }elseif (TypeHint::isScalarType($type)) { |
|
| 17 | 17 | return new ScalarTypeContainer($type); |
| 18 | - }else{ |
|
| 18 | + }else { |
|
| 19 | 19 | return $builder->build($type); |
| 20 | 20 | } |
| 21 | 21 | }; |
| 22 | - if(TypeHint::isArray($type)){ |
|
| 22 | + if (TypeHint::isArray($type)) { |
|
| 23 | 23 | $container = ArrayContainer::create($type, $getter); |
| 24 | - }else{ |
|
| 24 | + }else { |
|
| 25 | 25 | $container = $getter($type); |
| 26 | 26 | } |
| 27 | 27 | return $container; |
@@ -13,15 +13,15 @@ |
||
| 13 | 13 | $getter = function($type)use($builder){ |
| 14 | 14 | if(!$type || $type == 'mixed'){ |
| 15 | 15 | return new MixedTypeContainer(); |
| 16 | - }elseif (TypeHint::isScalarType($type)){ |
|
| 16 | + } elseif (TypeHint::isScalarType($type)){ |
|
| 17 | 17 | return new ScalarTypeContainer($type); |
| 18 | - }else{ |
|
| 18 | + } else{ |
|
| 19 | 19 | return $builder->build($type); |
| 20 | 20 | } |
| 21 | 21 | }; |
| 22 | 22 | if(TypeHint::isArray($type)){ |
| 23 | 23 | $container = ArrayContainer::create($type, $getter); |
| 24 | - }else{ |
|
| 24 | + } else{ |
|
| 25 | 25 | $container = $getter($type); |
| 26 | 26 | } |
| 27 | 27 | return $container; |
@@ -25,13 +25,13 @@ |
||
| 25 | 25 | $container->setDescription($ann->description); |
| 26 | 26 | $container->setSummary($ann->summary); |
| 27 | 27 | |
| 28 | - foreach ($properties as $i){ |
|
| 29 | - $isOption = array_key_exists($i->getName(), $default) && $default[$i->getName()] !==null; |
|
| 28 | + foreach ($properties as $i) { |
|
| 29 | + $isOption = array_key_exists($i->getName(), $default) && $default[$i->getName()] !== null; |
|
| 30 | 30 | $container->setProperty($i->getName(), new PropertyMeta( |
| 31 | 31 | $i->getName(), |
| 32 | 32 | null, |
| 33 | 33 | $isOption, |
| 34 | - $isOption?$default[$i->getName()]:null |
|
| 34 | + $isOption ? $default[$i->getName()] : null |
|
| 35 | 35 | )); |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | public function __invoke(EntityContainer $container, $ann) |
| 17 | 17 | { |
| 18 | 18 | $meta = $container->getProperty($ann->name); |
| 19 | - if(!$meta){ |
|
| 19 | + if (!$meta) { |
|
| 20 | 20 | $meta = new PropertyMeta($ann->name); |
| 21 | 21 | $container->setProperty($ann->name, $meta); |
| 22 | 22 | } |
@@ -19,25 +19,25 @@ |
||
| 19 | 19 | public function __invoke(EntityContainer $container, $ann) |
| 20 | 20 | { |
| 21 | 21 | $params = new AnnotationParams($ann->description, 3); |
| 22 | - if($params->count()){ |
|
| 22 | + if ($params->count()) { |
|
| 23 | 23 | |
| 24 | 24 | $target = $ann->parent->name; |
| 25 | 25 | $property = $container->getProperty($target); |
| 26 | 26 | $property or \PhpBoot\abort($container->getClassName()." property $target not exist "); |
| 27 | - if($params->count()>1){ |
|
| 27 | + if ($params->count()>1) { |
|
| 28 | 28 | $property->validation = [$params->getParam(0), $params->getParam(1)]; |
| 29 | - }else{ |
|
| 29 | + }else { |
|
| 30 | 30 | $property->validation = $params->getParam(0); |
| 31 | - if($property->validation){ |
|
| 31 | + if ($property->validation) { |
|
| 32 | 32 | $v = new Validator(); |
| 33 | 33 | $v->rule($property->validation, $property->name); |
| 34 | - if($v->hasRule('optional', $property->name)){ |
|
| 34 | + if ($v->hasRule('optional', $property->name)) { |
|
| 35 | 35 | $property->isOptional = true; |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - }else{ |
|
| 40 | + }else { |
|
| 41 | 41 | \PhpBoot\abort(new AnnotationSyntaxException( |
| 42 | 42 | "The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::{$ann->parent->name} require 1 param, 0 given" |
| 43 | 43 | )); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | $property or \PhpBoot\abort($container->getClassName()." property $target not exist "); |
| 27 | 27 | if($params->count()>1){ |
| 28 | 28 | $property->validation = [$params->getParam(0), $params->getParam(1)]; |
| 29 | - }else{ |
|
| 29 | + } else{ |
|
| 30 | 30 | $property->validation = $params->getParam(0); |
| 31 | 31 | if($property->validation){ |
| 32 | 32 | $v = new Validator(); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - }else{ |
|
| 40 | + } else{ |
|
| 41 | 41 | \PhpBoot\abort(new AnnotationSyntaxException( |
| 42 | 42 | "The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::{$ann->parent->name} require 1 param, 0 given" |
| 43 | 43 | )); |
@@ -23,21 +23,21 @@ |
||
| 23 | 23 | public function __invoke(EntityContainer $container, $ann, EntityContainerBuilder $builder) |
| 24 | 24 | { |
| 25 | 25 | $params = new AnnotationParams($ann->description, 3); |
| 26 | - if($params->count()){ |
|
| 26 | + if ($params->count()) { |
|
| 27 | 27 | $type = $params->getParam(0); |
| 28 | 28 | //TODO 校验type类型 |
| 29 | 29 | $target = $ann->parent->name; |
| 30 | 30 | $property = $container->getProperty($target); |
| 31 | 31 | $property or \PhpBoot\abort($container->getClassName()." property $target not exist "); |
| 32 | - if($type == null || $type == 'mixed'){ |
|
| 32 | + if ($type == null || $type == 'mixed') { |
|
| 33 | 33 | $property->container = new MixedTypeContainer(); |
| 34 | - } else{ |
|
| 34 | + }else { |
|
| 35 | 35 | // TODO 判断$type是否匹配 |
| 36 | 36 | $property->type = TypeHint::normalize($type, $container->getClassName()); |
| 37 | 37 | // TODO 防止递归死循环 |
| 38 | 38 | $property->container = ContainerFactory::create($builder, $property->type); |
| 39 | 39 | } |
| 40 | - }else{ |
|
| 40 | + }else { |
|
| 41 | 41 | \PhpBoot\abort(new AnnotationSyntaxException( |
| 42 | 42 | "The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::{$ann->parent->name} require 1 param, 0 given" |
| 43 | 43 | )); |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | // TODO 防止递归死循环 |
| 38 | 38 | $property->container = ContainerFactory::create($builder, $property->type); |
| 39 | 39 | } |
| 40 | - }else{ |
|
| 40 | + } else{ |
|
| 41 | 41 | \PhpBoot\abort(new AnnotationSyntaxException( |
| 42 | 42 | "The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::{$ann->parent->name} require 1 param, 0 given" |
| 43 | 43 | )); |
@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | TypeHint::isArray($type) or \PhpBoot\abort(new \InvalidArgumentException("type $type is not array")); |
| 18 | 18 | $elementType = $type; |
| 19 | 19 | $loops = 0; |
| 20 | - while(TypeHint::isArray($elementType)){ |
|
| 20 | + while (TypeHint::isArray($elementType)) { |
|
| 21 | 21 | $elementType = TypeHint::getArrayType($elementType); |
| 22 | 22 | $loops++; |
| 23 | 23 | } |
| 24 | 24 | $container = $getElementContainer($elementType); |
| 25 | 25 | |
| 26 | - while($loops--){ |
|
| 26 | + while ($loops--) { |
|
| 27 | 27 | $container = new self($container); |
| 28 | 28 | } |
| 29 | 29 | return $container; |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | is_array($data) or \PhpBoot\abort(new \InvalidArgumentException('the first param is required to be array')); |
| 44 | 44 | $res = []; |
| 45 | - foreach ($data as $k=>$v){ |
|
| 45 | + foreach ($data as $k=>$v) { |
|
| 46 | 46 | $res[$k] = $this->container->make($v, $validate); |
| 47 | 47 | } |
| 48 | 48 | return $res; |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | |
| 11 | 11 | class DIMetaLoader extends ContainerBuilder |
| 12 | 12 | { |
| 13 | - static $DEFAULT_ANNOTATIONS=[ |
|
| 13 | + static $DEFAULT_ANNOTATIONS = [ |
|
| 14 | 14 | [VarAnnotationHandler::class, "properties.*.children[?name=='var'][]"], |
| 15 | 15 | [InjectAnnotationHandler::class, "properties.*.children[?name=='inject'][]"] |
| 16 | 16 | ]; |