@@ -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 | } |
@@ -14,21 +14,21 @@ discard block |
||
14 | 14 | |
15 | 15 | public function make($data, $validate = true) |
16 | 16 | { |
17 | - if($data === null){ |
|
17 | + if ($data === null) { |
|
18 | 18 | return null; |
19 | 19 | } |
20 | 20 | $data instanceof \ArrayAccess || is_array($data) or \PhpBoot\abort(new \InvalidArgumentException("array is required by make {$this->className}, $data given")); |
21 | 21 | $className = $this->getClassName(); |
22 | 22 | $obj = new $className(); |
23 | 23 | $vld = new Validator(); |
24 | - foreach ($this->properties as $p){ |
|
25 | - if($p->container && isset($data[$p->name])){ |
|
24 | + foreach ($this->properties as $p) { |
|
25 | + if ($p->container && isset($data[$p->name])) { |
|
26 | 26 | $var = $data[$p->name]; |
27 | - if($p->container instanceof EntityContainer |
|
28 | - || $p->container instanceof ArrayContainer){ |
|
29 | - if(!$var){ |
|
27 | + if ($p->container instanceof EntityContainer |
|
28 | + || $p->container instanceof ArrayContainer) { |
|
29 | + if (!$var) { |
|
30 | 30 | $var = []; |
31 | - }elseif(is_string($var)){ |
|
31 | + }elseif (is_string($var)) { |
|
32 | 32 | $var = json_decode($var, true); |
33 | 33 | !json_last_error() or \PhpBoot\abort(new \InvalidArgumentException(__METHOD__.' failed while json_decode with '.json_last_error_msg())); |
34 | 34 | } |
@@ -36,18 +36,18 @@ discard block |
||
36 | 36 | $data[$p->name] = $p->container->make($var, $validate); |
37 | 37 | } |
38 | 38 | |
39 | - if($p->validation){ |
|
40 | - if(is_array($p->validation)){ |
|
39 | + if ($p->validation) { |
|
40 | + if (is_array($p->validation)) { |
|
41 | 41 | $vld->rule($p->validation[0], $p->name.'.'.$p->validation[1]); |
42 | - }else{ |
|
42 | + }else { |
|
43 | 43 | $vld->rule($p->validation, $p->name); |
44 | 44 | } |
45 | 45 | } |
46 | - if(!$p->isOptional && !$vld->hasRule('optional', $p->name)){ |
|
46 | + if (!$p->isOptional && !$vld->hasRule('optional', $p->name)) { |
|
47 | 47 | $vld->rule('required', $p->name); |
48 | 48 | } |
49 | 49 | } |
50 | - if($validate){ |
|
50 | + if ($validate) { |
|
51 | 51 | $vld = $vld->withData($data); |
52 | 52 | $vld->validate() or \PhpBoot\abort( |
53 | 53 | new \InvalidArgumentException( |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | ); |
60 | 60 | } |
61 | 61 | |
62 | - foreach ($this->properties as $p){ |
|
63 | - if(isset($data[$p->name])){ |
|
62 | + foreach ($this->properties as $p) { |
|
63 | + if (isset($data[$p->name])) { |
|
64 | 64 | $obj->{$p->name} = $data[$p->name]; |
65 | 65 | } |
66 | 66 | } |
@@ -72,32 +72,32 @@ discard block |
||
72 | 72 | { |
73 | 73 | $className = $this->getClassName(); |
74 | 74 | $obj = new $className(); |
75 | - foreach ($this->properties as $p){ |
|
76 | - if($p->isOptional){ |
|
75 | + foreach ($this->properties as $p) { |
|
76 | + if ($p->isOptional) { |
|
77 | 77 | $obj->{$p->name} = $p->default; |
78 | - }elseif($p->container){ |
|
78 | + }elseif ($p->container) { |
|
79 | 79 | $var = $p->container->makeExample(); |
80 | 80 | $obj->{$p->name} = $var; |
81 | - }else{ |
|
81 | + }else { |
|
82 | 82 | $obj->{$p->name} = null; |
83 | 83 | } |
84 | 84 | |
85 | 85 | } |
86 | 86 | return $obj; |
87 | 87 | } |
88 | - public function getProperty($target){ |
|
89 | - if(array_key_exists($target, $this->properties)){ |
|
88 | + public function getProperty($target) { |
|
89 | + if (array_key_exists($target, $this->properties)) { |
|
90 | 90 | return $this->properties[$target]; |
91 | 91 | } |
92 | 92 | return null; |
93 | 93 | } |
94 | - public function setProperty($target, PropertyMeta $meta){ |
|
94 | + public function setProperty($target, PropertyMeta $meta) { |
|
95 | 95 | $this->properties[$target] = $meta; |
96 | 96 | } |
97 | 97 | /** |
98 | 98 | * @return PropertyMeta[] |
99 | 99 | */ |
100 | - public function getProperties(){ |
|
100 | + public function getProperties() { |
|
101 | 101 | return $this->properties; |
102 | 102 | } |
103 | 103 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | /** |
158 | 158 | * @var PropertyMeta[] |
159 | 159 | */ |
160 | - private $properties=[]; |
|
160 | + private $properties = []; |
|
161 | 161 | |
162 | 162 | /** |
163 | 163 | * @var string |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | /** |
168 | 168 | * @var string |
169 | 169 | */ |
170 | - private $description=''; |
|
170 | + private $description = ''; |
|
171 | 171 | /** |
172 | 172 | * @var string |
173 | 173 | */ |
174 | - private $summary=''; |
|
174 | + private $summary = ''; |
|
175 | 175 | |
176 | 176 | /** |
177 | 177 | * @var string |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | || $p->container instanceof ArrayContainer){ |
29 | 29 | if(!$var){ |
30 | 30 | $var = []; |
31 | - }elseif(is_string($var)){ |
|
31 | + } elseif(is_string($var)){ |
|
32 | 32 | $var = json_decode($var, true); |
33 | 33 | !json_last_error() or \PhpBoot\abort(new \InvalidArgumentException(__METHOD__.' failed while json_decode with '.json_last_error_msg())); |
34 | 34 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | if($p->validation){ |
40 | 40 | if(is_array($p->validation)){ |
41 | 41 | $vld->rule($p->validation[0], $p->name.'.'.$p->validation[1]); |
42 | - }else{ |
|
42 | + } else{ |
|
43 | 43 | $vld->rule($p->validation, $p->name); |
44 | 44 | } |
45 | 45 | } |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | foreach ($this->properties as $p){ |
76 | 76 | if($p->isOptional){ |
77 | 77 | $obj->{$p->name} = $p->default; |
78 | - }elseif($p->container){ |
|
78 | + } elseif($p->container){ |
|
79 | 79 | $var = $p->container->makeExample(); |
80 | 80 | $obj->{$p->name} = $var; |
81 | - }else{ |
|
81 | + } else{ |
|
82 | 82 | $obj->{$p->name} = null; |
83 | 83 | } |
84 | 84 |
@@ -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 | )); |