@@ -26,19 +26,19 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function offsetExists($offset) |
28 | 28 | { |
29 | - if(is_array($this->obj)){ |
|
29 | + if (is_array($this->obj)) { |
|
30 | 30 | return array_key_exists($offset, $this->obj); |
31 | - }elseif(self::hasProperty($this->obj, $offset)){ |
|
31 | + }elseif (self::hasProperty($this->obj, $offset)) { |
|
32 | 32 | return true; |
33 | - }elseif(method_exists($this->obj, 'has')){ |
|
33 | + }elseif (method_exists($this->obj, 'has')) { |
|
34 | 34 | return $this->obj->has($offset); |
35 | - }elseif(method_exists($this->obj, $method = 'has'.ucfirst($offset))){ |
|
35 | + }elseif (method_exists($this->obj, $method = 'has'.ucfirst($offset))) { |
|
36 | 36 | return $this->obj->{$method}($offset); |
37 | - }elseif(method_exists($this->obj, $method = 'get'.ucfirst($offset))){ |
|
37 | + }elseif (method_exists($this->obj, $method = 'get'.ucfirst($offset))) { |
|
38 | 38 | return $this->obj->{$method}() !== null; |
39 | - }elseif(method_exists($this->obj, 'get')){ |
|
39 | + }elseif (method_exists($this->obj, 'get')) { |
|
40 | 40 | return $this->obj->get($offset) !== null; |
41 | - }else{ |
|
41 | + }else { |
|
42 | 42 | return false; |
43 | 43 | } |
44 | 44 | } |
@@ -55,18 +55,18 @@ discard block |
||
55 | 55 | public function offsetGet($offset) |
56 | 56 | { |
57 | 57 | $res = null; |
58 | - if(is_array($this->obj)){ |
|
58 | + if (is_array($this->obj)) { |
|
59 | 59 | $res = &$this->obj[$offset]; |
60 | - }elseif(self::hasProperty($this->obj, $offset)){ |
|
60 | + }elseif (self::hasProperty($this->obj, $offset)) { |
|
61 | 61 | $res = &$this->obj->{$offset}; |
62 | - }elseif(method_exists($this->obj, 'get')){ |
|
62 | + }elseif (method_exists($this->obj, 'get')) { |
|
63 | 63 | $res = $this->obj->get($offset); |
64 | - }elseif(method_exists($this->obj, $method = 'get'.ucfirst($offset))){ |
|
64 | + }elseif (method_exists($this->obj, $method = 'get'.ucfirst($offset))) { |
|
65 | 65 | $res = $this->obj->{$method}(); |
66 | - }else{ |
|
66 | + }else { |
|
67 | 67 | throw new \InvalidArgumentException("offsetGet($offset) failed"); |
68 | 68 | } |
69 | - if(is_array($res) || is_object($res)){ |
|
69 | + if (is_array($res) || is_object($res)) { |
|
70 | 70 | return new self($res); |
71 | 71 | } |
72 | 72 | return $res; |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function offsetSet($offset, $value) |
88 | 88 | { |
89 | - if(is_array($this->obj)){ |
|
89 | + if (is_array($this->obj)) { |
|
90 | 90 | $this->obj[$offset] = $value; |
91 | - }elseif(self::hasProperty($this->obj, $offset)){ |
|
91 | + }elseif (self::hasProperty($this->obj, $offset)) { |
|
92 | 92 | $this->obj->{$offset} = $value; |
93 | - }elseif(method_exists($this->obj, 'set')){ |
|
93 | + }elseif (method_exists($this->obj, 'set')) { |
|
94 | 94 | $this->obj->set($offset, $value); |
95 | - }elseif(method_exists($this->obj, $method = 'set'.ucfirst($offset))){ |
|
95 | + }elseif (method_exists($this->obj, $method = 'set'.ucfirst($offset))) { |
|
96 | 96 | $this->obj->{$method}($value); |
97 | - }else{ |
|
97 | + }else { |
|
98 | 98 | throw new \BadMethodCallException("can not set $offset"); |
99 | 99 | } |
100 | 100 | } |
@@ -110,35 +110,35 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function offsetUnset($offset) |
112 | 112 | { |
113 | - if(is_array($this->obj)){ |
|
113 | + if (is_array($this->obj)) { |
|
114 | 114 | unset($this->obj[$offset]); |
115 | - }elseif(self::hasProperty($this->obj, $offset)){ |
|
115 | + }elseif (self::hasProperty($this->obj, $offset)) { |
|
116 | 116 | unset($this->obj->{$offset}); |
117 | - }elseif(method_exists($this->obj, 'remove')){ |
|
117 | + }elseif (method_exists($this->obj, 'remove')) { |
|
118 | 118 | $this->obj->remove($offset); |
119 | - }elseif(method_exists($this->obj, $method = 'remove'.ucfirst($offset))){ |
|
119 | + }elseif (method_exists($this->obj, $method = 'remove'.ucfirst($offset))) { |
|
120 | 120 | $this->obj->$method(); |
121 | - }else{ |
|
121 | + }else { |
|
122 | 122 | throw new \InvalidArgumentException("offsetUnset($offset) failed"); |
123 | 123 | } |
124 | 124 | } |
125 | - static public function strip($obj){ |
|
126 | - if($obj instanceof self){ |
|
125 | + static public function strip($obj) { |
|
126 | + if ($obj instanceof self) { |
|
127 | 127 | return $obj->obj; |
128 | 128 | } |
129 | 129 | return $obj; |
130 | 130 | } |
131 | 131 | static function hasProperty($object, $name) |
132 | 132 | { |
133 | - if(!is_object($object)){ |
|
133 | + if (!is_object($object)) { |
|
134 | 134 | return false; |
135 | 135 | } |
136 | 136 | $class = new \ReflectionClass($object); |
137 | - if(!$class->hasProperty($name)){ |
|
137 | + if (!$class->hasProperty($name)) { |
|
138 | 138 | return false; |
139 | 139 | } |
140 | 140 | $property = $class->getProperty($name); |
141 | - if(!$property){ |
|
141 | + if (!$property) { |
|
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | return $property->isPublic(); |
@@ -28,17 +28,17 @@ discard block |
||
28 | 28 | { |
29 | 29 | if(is_array($this->obj)){ |
30 | 30 | return array_key_exists($offset, $this->obj); |
31 | - }elseif(self::hasProperty($this->obj, $offset)){ |
|
31 | + } elseif(self::hasProperty($this->obj, $offset)){ |
|
32 | 32 | return true; |
33 | - }elseif(method_exists($this->obj, 'has')){ |
|
33 | + } elseif(method_exists($this->obj, 'has')){ |
|
34 | 34 | return $this->obj->has($offset); |
35 | - }elseif(method_exists($this->obj, $method = 'has'.ucfirst($offset))){ |
|
35 | + } elseif(method_exists($this->obj, $method = 'has'.ucfirst($offset))){ |
|
36 | 36 | return $this->obj->{$method}($offset); |
37 | - }elseif(method_exists($this->obj, $method = 'get'.ucfirst($offset))){ |
|
37 | + } elseif(method_exists($this->obj, $method = 'get'.ucfirst($offset))){ |
|
38 | 38 | return $this->obj->{$method}() !== null; |
39 | - }elseif(method_exists($this->obj, 'get')){ |
|
39 | + } elseif(method_exists($this->obj, 'get')){ |
|
40 | 40 | return $this->obj->get($offset) !== null; |
41 | - }else{ |
|
41 | + } else{ |
|
42 | 42 | return false; |
43 | 43 | } |
44 | 44 | } |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | $res = null; |
58 | 58 | if(is_array($this->obj)){ |
59 | 59 | $res = &$this->obj[$offset]; |
60 | - }elseif(self::hasProperty($this->obj, $offset)){ |
|
60 | + } elseif(self::hasProperty($this->obj, $offset)){ |
|
61 | 61 | $res = &$this->obj->{$offset}; |
62 | - }elseif(method_exists($this->obj, 'get')){ |
|
62 | + } elseif(method_exists($this->obj, 'get')){ |
|
63 | 63 | $res = $this->obj->get($offset); |
64 | - }elseif(method_exists($this->obj, $method = 'get'.ucfirst($offset))){ |
|
64 | + } elseif(method_exists($this->obj, $method = 'get'.ucfirst($offset))){ |
|
65 | 65 | $res = $this->obj->{$method}(); |
66 | - }else{ |
|
66 | + } else{ |
|
67 | 67 | throw new \InvalidArgumentException("offsetGet($offset) failed"); |
68 | 68 | } |
69 | 69 | if(is_array($res) || is_object($res)){ |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | { |
89 | 89 | if(is_array($this->obj)){ |
90 | 90 | $this->obj[$offset] = $value; |
91 | - }elseif(self::hasProperty($this->obj, $offset)){ |
|
91 | + } elseif(self::hasProperty($this->obj, $offset)){ |
|
92 | 92 | $this->obj->{$offset} = $value; |
93 | - }elseif(method_exists($this->obj, 'set')){ |
|
93 | + } elseif(method_exists($this->obj, 'set')){ |
|
94 | 94 | $this->obj->set($offset, $value); |
95 | - }elseif(method_exists($this->obj, $method = 'set'.ucfirst($offset))){ |
|
95 | + } elseif(method_exists($this->obj, $method = 'set'.ucfirst($offset))){ |
|
96 | 96 | $this->obj->{$method}($value); |
97 | - }else{ |
|
97 | + } else{ |
|
98 | 98 | throw new \BadMethodCallException("can not set $offset"); |
99 | 99 | } |
100 | 100 | } |
@@ -112,13 +112,13 @@ discard block |
||
112 | 112 | { |
113 | 113 | if(is_array($this->obj)){ |
114 | 114 | unset($this->obj[$offset]); |
115 | - }elseif(self::hasProperty($this->obj, $offset)){ |
|
115 | + } elseif(self::hasProperty($this->obj, $offset)){ |
|
116 | 116 | unset($this->obj->{$offset}); |
117 | - }elseif(method_exists($this->obj, 'remove')){ |
|
117 | + } elseif(method_exists($this->obj, 'remove')){ |
|
118 | 118 | $this->obj->remove($offset); |
119 | - }elseif(method_exists($this->obj, $method = 'remove'.ucfirst($offset))){ |
|
119 | + } elseif(method_exists($this->obj, $method = 'remove'.ucfirst($offset))){ |
|
120 | 120 | $this->obj->$method(); |
121 | - }else{ |
|
121 | + } else{ |
|
122 | 122 | throw new \InvalidArgumentException("offsetUnset($offset) failed"); |
123 | 123 | } |
124 | 124 | } |
@@ -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 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | abstract protected function createContainer($className); |
69 | 69 | |
70 | 70 | |
71 | - protected function handleAnnotation($handlerName, $container, $ann){ |
|
71 | + protected function handleAnnotation($handlerName, $container, $ann) { |
|
72 | 72 | $handler = new $handlerName(); |
73 | 73 | return $handler($container, $ann); |
74 | 74 | } |
@@ -80,15 +80,15 @@ discard block |
||
80 | 80 | { |
81 | 81 | $container = $this->createContainer($className); |
82 | 82 | $anns = AnnotationReader::read($className, $this->cache); |
83 | - foreach ($this->annotations as $i){ |
|
83 | + foreach ($this->annotations as $i) { |
|
84 | 84 | list($class, $target) = $i; |
85 | 85 | |
86 | 86 | $found = \JmesPath\search($target, $anns); |
87 | - if(is_array($found)){ |
|
88 | - foreach ($found as $f){ |
|
89 | - $this->handleAnnotation($class, $container,$f); //TODO 支持 |
|
87 | + if (is_array($found)) { |
|
88 | + foreach ($found as $f) { |
|
89 | + $this->handleAnnotation($class, $container, $f); //TODO 支持 |
|
90 | 90 | } |
91 | - }else{ |
|
91 | + }else { |
|
92 | 92 | $this->handleAnnotation($class, $container, $found); |
93 | 93 | } |
94 | 94 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | /** |
99 | 99 | * @var array |
100 | 100 | */ |
101 | - private $annotations=[]; |
|
101 | + private $annotations = []; |
|
102 | 102 | /** |
103 | 103 | * @var Cache |
104 | 104 | */ |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | $meta = $this->buildWithoutCache($className); |
50 | 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 | 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 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | foreach ($found as $f){ |
89 | 89 | $this->handleAnnotation($class, $container,$f); //TODO 支持 |
90 | 90 | } |
91 | - }else{ |
|
91 | + } else{ |
|
92 | 92 | $this->handleAnnotation($class, $container, $found); |
93 | 93 | } |
94 | 94 | } |
@@ -13,11 +13,11 @@ discard block |
||
13 | 13 | * @param AnnotationTag[] $children |
14 | 14 | * @param AnnotationBlock|null $parent |
15 | 15 | */ |
16 | - public function __construct($name='', |
|
17 | - $summary='', |
|
18 | - $description='', |
|
19 | - $children=[], |
|
20 | - $parent=null) |
|
16 | + public function __construct($name = '', |
|
17 | + $summary = '', |
|
18 | + $description = '', |
|
19 | + $children = [], |
|
20 | + $parent = null) |
|
21 | 21 | { |
22 | 22 | $this->name = $name; |
23 | 23 | $this->summary = $summary; |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * @var string |
39 | 39 | */ |
40 | - public $description=''; |
|
40 | + public $description = ''; |
|
41 | 41 | /** |
42 | 42 | * @var AnnotationTag[] |
43 | 43 | */ |
44 | - public $children=[]; |
|
44 | + public $children = []; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @var AnnotationTag|null |
@@ -23,12 +23,12 @@ |
||
23 | 23 | */ |
24 | 24 | static public function register(Application $app, |
25 | 25 | callable $callback = null, |
26 | - $prefix='/docs') |
|
26 | + $prefix = '/docs') |
|
27 | 27 | { |
28 | - $app->addRoute('GET', $prefix.'/swagger.json', function (Application $app)use($callback){ |
|
28 | + $app->addRoute('GET', $prefix.'/swagger.json', function(Application $app)use($callback){ |
|
29 | 29 | $swagger = new Swagger(); |
30 | 30 | $swagger->appendControllers($app, $app->getControllers()); |
31 | - if($callback){ |
|
31 | + if ($callback) { |
|
32 | 32 | $callback($swagger); |
33 | 33 | } |
34 | 34 | return new Response($swagger->toJson()); |
@@ -64,12 +64,12 @@ |
||
64 | 64 | * The value overrides the Swagger Object schemes definition. |
65 | 65 | * @var string[] |
66 | 66 | */ |
67 | - public $schemes=['http']; |
|
67 | + public $schemes = ['http']; |
|
68 | 68 | /** |
69 | 69 | * Declares this operation to be deprecated. Usage of the declared operation should be refrained. Default value is false. |
70 | 70 | * @var bool |
71 | 71 | */ |
72 | - public $deprecated=false; |
|
72 | + public $deprecated = false; |
|
73 | 73 | /** |
74 | 74 | * A declaration of which security schemes are applied for this operation. The list of values describes |
75 | 75 | * alternative security schemes that can be used (that is, there is a logical OR between the security |
@@ -52,18 +52,18 @@ |
||
52 | 52 | * A list of MIME types the APIs can produce. This is global to all APIs but can be overridden on specific API calls. Value MUST be as described under Mime Types. |
53 | 53 | * @var string[] |
54 | 54 | */ |
55 | - public $produces= ['application/json']; |
|
55 | + public $produces = ['application/json']; |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @var PathItemObject[] |
59 | 59 | */ |
60 | - public $paths=[]; |
|
60 | + public $paths = []; |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * An object to hold data types produced and consumed by operations. |
64 | 64 | * @var RefSchemaObject[]|SimpleModelSchemaObject[]|PrimitiveSchemaObject[]|ArraySchemaObject[] |
65 | 65 | */ |
66 | - public $definitions=[]; |
|
66 | + public $definitions = []; |
|
67 | 67 | /** |
68 | 68 | * An object to hold parameters that can be used across operations. This property does not define global |
69 | 69 | * parameters for all operations. |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * Required. The title of the application. |
10 | 10 | * @var string |
11 | 11 | */ |
12 | - public $title=''; |
|
12 | + public $title = ''; |
|
13 | 13 | /** |
14 | 14 | * A short description of the application. GFM syntax can be used for rich text representation |
15 | 15 | * @var string |
@@ -34,5 +34,5 @@ discard block |
||
34 | 34 | * Required Provides the version of the application API (not to be confused with the specification version) |
35 | 35 | * @var string |
36 | 36 | */ |
37 | - public $version=''; |
|
37 | + public $version = ''; |
|
38 | 38 | } |
39 | 39 | \ No newline at end of file |
@@ -10,7 +10,7 @@ |
||
10 | 10 | * representation. |
11 | 11 | * @var string |
12 | 12 | */ |
13 | - public $description=''; |
|
13 | + public $description = ''; |
|
14 | 14 | /** |
15 | 15 | * A definition of the response structure. It can be a primitive, an array or an object. If this field |
16 | 16 | * does not exist, it means no content is returned as part of the response. As an extension to the Schema |
@@ -55,12 +55,12 @@ |
||
55 | 55 | */ |
56 | 56 | public function rule($rule, $fields) |
57 | 57 | { |
58 | - if(is_string($rule)){ |
|
58 | + if (is_string($rule)) { |
|
59 | 59 | $rules = explode('|', $rule); |
60 | - foreach ($rules as $r){ |
|
60 | + foreach ($rules as $r) { |
|
61 | 61 | $params = explode(':', trim($r)); |
62 | 62 | $rule = $params[0]; |
63 | - $params = isset($params[1])?explode(',', $params[1]):[]; |
|
63 | + $params = isset($params[1]) ? explode(',', $params[1]) : []; |
|
64 | 64 | |
65 | 65 | call_user_func_array([$this, 'parent::rule'], array_merge([$rule, $fields], $params)); |
66 | 66 |