@@ -73,7 +73,7 @@ |
||
73 | 73 | } |
74 | 74 | } |
75 | 75 | /** |
76 | - * @param $className |
|
76 | + * @param string $className |
|
77 | 77 | * @return self |
78 | 78 | */ |
79 | 79 | static function readWithoutCache($className) |
@@ -62,13 +62,13 @@ |
||
62 | 62 | $meta = self::readWithoutCache($className); |
63 | 63 | $cache->set($key, $meta, 0, $fileName?new ClassModifiedChecker($className):null); |
64 | 64 | return $meta; |
65 | - }catch (\Exception $e){ |
|
65 | + } catch (\Exception $e){ |
|
66 | 66 | $cache->set($key, $e->getMessage(), 0, $fileName?new ClassModifiedChecker($className):null); |
67 | 67 | throw $e; |
68 | 68 | } |
69 | - }elseif(is_string($res)){ |
|
69 | + } elseif(is_string($res)){ |
|
70 | 70 | \PhpBoot\abort($res); |
71 | - }else{ |
|
71 | + } else{ |
|
72 | 72 | return $res; |
73 | 73 | } |
74 | 74 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | } |
46 | 46 | class AnnotationReader implements \ArrayAccess |
47 | 47 | { |
48 | - static public function createDocBlockFactory(){ |
|
48 | + static public function createDocBlockFactory() { |
|
49 | 49 | $fqsenResolver = new FqsenResolver(); |
50 | - $tagFactory = new StandardTagFactory($fqsenResolver,[]); |
|
50 | + $tagFactory = new StandardTagFactory($fqsenResolver, []); |
|
51 | 51 | $descriptionFactory = new DescriptionFactory($tagFactory); |
52 | 52 | $tagFactory->addService($descriptionFactory); |
53 | 53 | $tagFactory->addService(new TypeResolver($fqsenResolver)); |
@@ -72,22 +72,22 @@ discard block |
||
72 | 72 | self::assertAnnotationEnabled(); |
73 | 73 | $rfl = new \ReflectionClass($className) or \PhpBoot\abort("load class $className failed"); |
74 | 74 | $fileName = $rfl->getFileName(); |
75 | - $key = str_replace('\\','.',self::class).md5($fileName.$className); |
|
75 | + $key = str_replace('\\', '.', self::class).md5($fileName.$className); |
|
76 | 76 | $oldData = null; |
77 | - $cache = new CheckableCache($localCache?:new ApcCache()); |
|
77 | + $cache = new CheckableCache($localCache ?: new ApcCache()); |
|
78 | 78 | $res = $cache->get('ann:'.$key, null, $oldData, false); |
79 | - if($res === null){ |
|
80 | - try{ |
|
79 | + if ($res === null) { |
|
80 | + try { |
|
81 | 81 | $meta = self::readWithoutCache($className); |
82 | - $cache->set($key, $meta, 0, $fileName?new ClassModifiedChecker($className):null); |
|
82 | + $cache->set($key, $meta, 0, $fileName ? new ClassModifiedChecker($className) : null); |
|
83 | 83 | return $meta; |
84 | - }catch (\Exception $e){ |
|
85 | - $cache->set($key, $e->getMessage(), 0, $fileName?new ClassModifiedChecker($className):null); |
|
84 | + }catch (\Exception $e) { |
|
85 | + $cache->set($key, $e->getMessage(), 0, $fileName ? new ClassModifiedChecker($className) : null); |
|
86 | 86 | throw $e; |
87 | 87 | } |
88 | - }elseif(is_string($res)){ |
|
88 | + }elseif (is_string($res)) { |
|
89 | 89 | \PhpBoot\abort($res); |
90 | - }else{ |
|
90 | + }else { |
|
91 | 91 | return $res; |
92 | 92 | } |
93 | 93 | } |
@@ -104,19 +104,19 @@ discard block |
||
104 | 104 | $reader->class->name = $className; |
105 | 105 | |
106 | 106 | //method annotations |
107 | - foreach ($rfl->getMethods() as $i){ |
|
107 | + foreach ($rfl->getMethods() as $i) { |
|
108 | 108 | $block = self::readAnnotationBlock($i->getDocComment()); |
109 | 109 | $block->name = $i->getName(); |
110 | - $reader->methods[$i->getName()]=$block; |
|
110 | + $reader->methods[$i->getName()] = $block; |
|
111 | 111 | } |
112 | 112 | //property annotations |
113 | - foreach ($rfl->getProperties() as $i){ |
|
113 | + foreach ($rfl->getProperties() as $i) { |
|
114 | 114 | if ($i->isStatic()) { |
115 | 115 | continue; |
116 | 116 | } |
117 | 117 | $block = self::readAnnotationBlock($i->getDocComment()); |
118 | 118 | $block->name = $i->getName(); |
119 | - $reader->properties[$i->getName()]=$block; |
|
119 | + $reader->properties[$i->getName()] = $block; |
|
120 | 120 | } |
121 | 121 | while ($rfl = $rfl->getParentClass()) { |
122 | 122 | foreach ($rfl->getProperties(\ReflectionProperty::IS_PRIVATE) as $i) { |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | } |
126 | 126 | $block = self::readAnnotationBlock($i->getDocComment()); |
127 | 127 | $block->name = $i->getName(); |
128 | - $reader->properties[$i->getName()]=$block; |
|
128 | + $reader->properties[$i->getName()] = $block; |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | return $reader; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | static private function readAnnotationBlock($doc) |
135 | 135 | { |
136 | 136 | $annBlock = new AnnotationBlock(); |
137 | - if(empty($doc)){ |
|
137 | + if (empty($doc)) { |
|
138 | 138 | return $annBlock; |
139 | 139 | } |
140 | 140 | $docFactory = AnnotationReader::createDocBlockFactory(); |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | $annTag->parent = $annBlock; |
150 | 150 | $annTag->description = strval($desc); |
151 | 151 | $annTag->name = $tag->getName(); |
152 | - $annTag->children=[]; |
|
153 | - if($desc){ |
|
152 | + $annTag->children = []; |
|
153 | + if ($desc) { |
|
154 | 154 | $output = new AnnotationTagsOutput(); |
155 | 155 | $desc->render($output); |
156 | 156 | foreach ($output->tags as $child) { |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | * @var AnnotationBlock[] |
175 | 175 | */ |
176 | 176 | |
177 | - public $methods=[]; |
|
177 | + public $methods = []; |
|
178 | 178 | /** |
179 | 179 | * @var AnnotationBlock[] |
180 | 180 | */ |
181 | - public $properties=[]; |
|
181 | + public $properties = []; |
|
182 | 182 | |
183 | 183 | public function offsetExists($offset) |
184 | 184 | { |
@@ -8,7 +8,6 @@ |
||
8 | 8 | /** |
9 | 9 | * AnnotationTag constructor. |
10 | 10 | * @param string $name |
11 | - * @param string $summary |
|
12 | 11 | * @param string $description |
13 | 12 | * @param array $children |
14 | 13 | * @param AnnotationBlock|AnnotationTag|null $parent |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | * @param array $children |
14 | 14 | * @param AnnotationBlock|AnnotationTag|null $parent |
15 | 15 | */ |
16 | - public function __construct($name='', |
|
17 | - $description='', |
|
18 | - $children=[], |
|
19 | - $parent=null) |
|
16 | + public function __construct($name = '', |
|
17 | + $description = '', |
|
18 | + $children = [], |
|
19 | + $parent = null) |
|
20 | 20 | { |
21 | 21 | $this->name = $name; |
22 | 22 | $this->description = $description; |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @var string |
33 | 33 | */ |
34 | - public $description=''; |
|
34 | + public $description = ''; |
|
35 | 35 | /** |
36 | 36 | * @var AnnotationBlock[] |
37 | 37 | */ |
38 | - public $children=[]; |
|
38 | + public $children = []; |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @var AnnotationBlock|null |
@@ -375,7 +375,7 @@ |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
378 | - * @return \string[] |
|
378 | + * @return string[] |
|
379 | 379 | */ |
380 | 380 | public function getGlobalHooks() |
381 | 381 | { |
@@ -24,7 +24,6 @@ |
||
24 | 24 | use PhpBoot\DB\DB; |
25 | 25 | use PhpBoot\DI\DIContainerBuilder; |
26 | 26 | use PhpBoot\DI\Traits\EnableDIAnnotations; |
27 | -use PhpBoot\Lock\LocalAutoLock; |
|
28 | 27 | use PhpBoot\Utils\Logger; |
29 | 28 | use Psr\Container\ContainerExceptionInterface; |
30 | 29 | use Psr\Container\ContainerInterface; |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | |
84 | 84 | Request::class => \DI\factory([Application::class, 'createRequestFromGlobals']), |
85 | 85 | ]; |
86 | - if(function_exists('apc_fetch')){ |
|
86 | + if (function_exists('apc_fetch')) { |
|
87 | 87 | $default += [ |
88 | 88 | Cache::class => \DI\object(ApcCache::class) |
89 | 89 | ]; |
90 | - }else{ |
|
90 | + }else { |
|
91 | 91 | $default += [ |
92 | 92 | Cache::class => \DI\object(FilesystemCache::class) |
93 | 93 | ->constructorParameter('directory', sys_get_temp_dir()) |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | * @param string[] $hooks hook class names |
130 | 130 | * @return void |
131 | 131 | */ |
132 | - public function loadRoutesFromClass($className, $hooks=[]) |
|
132 | + public function loadRoutesFromClass($className, $hooks = []) |
|
133 | 133 | { |
134 | 134 | $cache = new CheckableCache($this->cache); |
135 | 135 | |
136 | - $key = 'loadRoutesFromClass:' . md5(__CLASS__ . ':' . $className); |
|
136 | + $key = 'loadRoutesFromClass:'.md5(__CLASS__.':'.$className); |
|
137 | 137 | $routes = $cache->get($key, $this); |
138 | 138 | |
139 | 139 | $controller = null; |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | $this->routes[] = [ |
151 | 151 | $method, |
152 | 152 | $uri, |
153 | - function (Application $app, Request $request) use ($cache, $className, $actionName, $controller) { |
|
153 | + function(Application $app, Request $request) use ($cache, $className, $actionName, $controller) { |
|
154 | 154 | |
155 | - $key = 'loadRoutesFromClass:route:' . md5(__CLASS__ . ':' . $className . ':' . $actionName); |
|
155 | + $key = 'loadRoutesFromClass:route:'.md5(__CLASS__.':'.$className.':'.$actionName); |
|
156 | 156 | |
157 | 157 | $routeInstance = $cache->get($key, $this); |
158 | 158 | if ($routeInstance == $this) { |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | * @param string[] $hooks |
181 | 181 | * @return void |
182 | 182 | */ |
183 | - public function loadRoutesFromPath($fromPath, $namespace = '', $hooks=[]) |
|
183 | + public function loadRoutesFromPath($fromPath, $namespace = '', $hooks = []) |
|
184 | 184 | { |
185 | 185 | $dir = @dir($fromPath); |
186 | 186 | |
187 | - $getEach = function () use ($dir) { |
|
187 | + $getEach = function() use ($dir) { |
|
188 | 188 | $name = $dir->read(); |
189 | 189 | if (!$name) { |
190 | 190 | return $name; |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | if ($entry == '.' || $entry == '..') { |
197 | 197 | continue; |
198 | 198 | } |
199 | - $path = $fromPath . '/' . str_replace('\\', '/', $entry); |
|
199 | + $path = $fromPath.'/'.str_replace('\\', '/', $entry); |
|
200 | 200 | if (is_file($path) && substr_compare($entry, '.php', strlen($entry) - 4, 4, true) == 0) { |
201 | - $class_name = $namespace . '\\' . substr($entry, 0, strlen($entry) - 4); |
|
201 | + $class_name = $namespace.'\\'.substr($entry, 0, strlen($entry) - 4); |
|
202 | 202 | $this->loadRoutesFromClass($class_name, $hooks); |
203 | - } else { |
|
203 | + }else { |
|
204 | 204 | //\Log::debug($path.' ignored'); |
205 | 205 | } |
206 | 206 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * @param callable $handler function(Application $app, Request $request):Response |
214 | 214 | * @param string[] $hooks |
215 | 215 | */ |
216 | - public function addRoute($method, $uri, callable $handler, $hooks=[]) |
|
216 | + public function addRoute($method, $uri, callable $handler, $hooks = []) |
|
217 | 217 | { |
218 | 218 | $this->routes[] = [$method, $uri, $handler, $hooks]; |
219 | 219 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | { |
240 | 240 | // TODO 把 Route里的异常处理 ExceptionRenderer 移到这里更妥? |
241 | 241 | $renderer = $this->get(ExceptionRenderer::class); |
242 | - try{ |
|
242 | + try { |
|
243 | 243 | if ($request == null) { |
244 | 244 | $request = $this->make(Request::class); |
245 | 245 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | } |
250 | 250 | $uri = rawurldecode($uri); |
251 | 251 | |
252 | - $next = function (Request $request)use($uri){ |
|
252 | + $next = function(Request $request)use($uri){ |
|
253 | 253 | $dispatcher = $this->getDispatcher(); |
254 | 254 | $res = $dispatcher->dispatch($request->getMethod(), $uri); |
255 | 255 | if ($res[0] == Dispatcher::FOUND) { |
@@ -258,10 +258,10 @@ discard block |
||
258 | 258 | $request->attributes->add($res[2]); |
259 | 259 | } |
260 | 260 | list($handler, $hooks) = $res[1]; |
261 | - $next = function (Request $request)use($handler){ |
|
261 | + $next = function(Request $request)use($handler){ |
|
262 | 262 | return $handler($this, $request); |
263 | 263 | }; |
264 | - foreach (array_reverse($hooks) as $hookName){ |
|
264 | + foreach (array_reverse($hooks) as $hookName) { |
|
265 | 265 | $next = function($request)use($hookName, $next){ |
266 | 266 | $hook = $this->get($hookName); |
267 | 267 | /**@var $hook HookInterface*/ |
@@ -274,12 +274,12 @@ discard block |
||
274 | 274 | \PhpBoot\abort(new NotFoundHttpException(), [$request->getMethod(), $uri]); |
275 | 275 | } elseif ($res[0] == Dispatcher::METHOD_NOT_ALLOWED) { |
276 | 276 | \PhpBoot\abort(new MethodNotAllowedHttpException($res[1]), [$request->getMethod(), $uri]); |
277 | - } else { |
|
277 | + }else { |
|
278 | 278 | \PhpBoot\abort("unknown dispatch return {$res[0]}"); |
279 | 279 | } |
280 | 280 | }; |
281 | 281 | |
282 | - foreach (array_reverse($this->getGlobalHooks()) as $hookName){ |
|
282 | + foreach (array_reverse($this->getGlobalHooks()) as $hookName) { |
|
283 | 283 | $next = function($request)use($hookName, $next){ |
284 | 284 | $hook = $this->get($hookName); |
285 | 285 | /**@var $hook HookInterface*/ |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | } |
295 | 295 | return $response; |
296 | 296 | |
297 | - }catch (\Exception $e){ |
|
297 | + }catch (\Exception $e) { |
|
298 | 298 | $renderer->render($e); |
299 | 299 | } |
300 | 300 |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $default += [ |
88 | 88 | Cache::class => \DI\object(ApcCache::class) |
89 | 89 | ]; |
90 | - }else{ |
|
90 | + } else{ |
|
91 | 91 | $default += [ |
92 | 92 | Cache::class => \DI\object(FilesystemCache::class) |
93 | 93 | ->constructorParameter('directory', sys_get_temp_dir()) |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | } |
271 | 271 | return $next($request); |
272 | 272 | |
273 | - }elseif ($res[0] == Dispatcher::NOT_FOUND) { |
|
273 | + } elseif ($res[0] == Dispatcher::NOT_FOUND) { |
|
274 | 274 | \PhpBoot\abort(new NotFoundHttpException(), [$request->getMethod(), $uri]); |
275 | 275 | } elseif ($res[0] == Dispatcher::METHOD_NOT_ALLOWED) { |
276 | 276 | \PhpBoot\abort(new MethodNotAllowedHttpException($res[1]), [$request->getMethod(), $uri]); |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | } |
295 | 295 | return $response; |
296 | 296 | |
297 | - }catch (\Exception $e){ |
|
297 | + } catch (\Exception $e){ |
|
298 | 298 | $renderer->render($e); |
299 | 299 | } |
300 | 300 |
@@ -4,6 +4,9 @@ |
||
4 | 4 | |
5 | 5 | class ClassModifiedChecker extends FileModifiedChecker |
6 | 6 | { |
7 | + /** |
|
8 | + * @param string $className |
|
9 | + */ |
|
7 | 10 | function __construct($className){ |
8 | 11 | $class = new \ReflectionClass($className); |
9 | 12 | $files = []; |
@@ -4,11 +4,11 @@ discard block |
||
4 | 4 | |
5 | 5 | class ClassModifiedChecker extends FileModifiedChecker |
6 | 6 | { |
7 | - function __construct($className){ |
|
7 | + function __construct($className) { |
|
8 | 8 | $class = new \ReflectionClass($className); |
9 | 9 | $files = []; |
10 | 10 | |
11 | - if($class->getFileName()){ |
|
11 | + if ($class->getFileName()) { |
|
12 | 12 | $files[] = $class->getFileName(); |
13 | 13 | self::getParentFileName($class, $files); |
14 | 14 | } |
@@ -18,15 +18,15 @@ discard block |
||
18 | 18 | static public function getParentFileName(\ReflectionClass $class, array &$files) |
19 | 19 | { |
20 | 20 | $parent = $class->getParentClass(); |
21 | - if(!$parent){ |
|
21 | + if (!$parent) { |
|
22 | 22 | return; |
23 | 23 | } |
24 | - if($parent->getFileName()){ |
|
24 | + if ($parent->getFileName()) { |
|
25 | 25 | $files[] = $parent->getParentClass(); |
26 | 26 | self::getParentFileName($parent, $files); |
27 | 27 | } |
28 | - foreach ($class->getInterfaces() as $interface){ |
|
29 | - if($interface->getFileName()){ |
|
28 | + foreach ($class->getInterfaces() as $interface) { |
|
29 | + if ($interface->getFileName()) { |
|
30 | 30 | $files[] = $interface->getFileName(); |
31 | 31 | self::getParentFileName($interface, $files); |
32 | 32 | } |
@@ -5,7 +5,6 @@ |
||
5 | 5 | use DI\FactoryInterface; |
6 | 6 | use \DI\InvokerInterface as DIInvokerInterface; |
7 | 7 | use Doctrine\Common\Cache\Cache; |
8 | -use PhpBoot\Cache\LocalCacheInterface; |
|
9 | 8 | use PhpBoot\Controller\Annotations\BindAnnotationHandler; |
10 | 9 | use PhpBoot\Controller\Annotations\ClassAnnotationHandler; |
11 | 10 | use PhpBoot\Controller\Annotations\HookAnnotationHandler; |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | class ControllerContainerBuilder extends ContainerBuilder |
21 | 21 | { |
22 | - static $DEFAULT_ANNOTATIONS=[ |
|
22 | + static $DEFAULT_ANNOTATIONS = [ |
|
23 | 23 | [ClassAnnotationHandler::class, 'class'], |
24 | 24 | [PathAnnotationHandler::class, "class.children[?name=='path']"], |
25 | 25 | [RouteAnnotationHandler::class, "methods.*.children[?name=='route'][]"], |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | Cache $cache, |
44 | 44 | array $annotations = null) |
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 |
@@ -45,7 +45,7 @@ |
||
45 | 45 | { |
46 | 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 |
@@ -91,7 +91,7 @@ |
||
91 | 91 | |
92 | 92 | /** |
93 | 93 | * 获取指定参数信息 |
94 | - * @param $name |
|
94 | + * @param string|null $name |
|
95 | 95 | * @return ParamMeta|null |
96 | 96 | */ |
97 | 97 | public function getParamMeta($name){ |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @param ParamMeta[] $paramMates |
17 | 17 | */ |
18 | - public function __construct(array $paramMates=[]){ |
|
18 | + public function __construct(array $paramMates = []) { |
|
19 | 19 | $this->paramMetas = $paramMates; |
20 | 20 | } |
21 | 21 | |
@@ -26,32 +26,32 @@ discard block |
||
26 | 26 | * @param array $reference |
27 | 27 | * @return void |
28 | 28 | */ |
29 | - public function handle(Application $app, Request $request, array &$params, array &$reference){ |
|
29 | + public function handle(Application $app, Request $request, array &$params, array &$reference) { |
|
30 | 30 | |
31 | 31 | $vld = new Validator(); |
32 | 32 | $req = ['request'=>$request]; |
33 | 33 | $requestArray = new ArrayAdaptor($req); |
34 | 34 | $inputs = []; |
35 | - foreach ($this->paramMetas as $k=>$meta){ |
|
36 | - if($meta->isPassedByReference){ |
|
35 | + foreach ($this->paramMetas as $k=>$meta) { |
|
36 | + if ($meta->isPassedByReference) { |
|
37 | 37 | // param PassedByReference is used to output |
38 | 38 | continue; |
39 | 39 | } |
40 | 40 | $source = \JmesPath\search($meta->source, $requestArray); |
41 | - if ($source !== null){ |
|
41 | + if ($source !== null) { |
|
42 | 42 | $source = ArrayAdaptor::strip($source); |
43 | - if($source instanceof ParameterBag){ |
|
43 | + if ($source instanceof ParameterBag) { |
|
44 | 44 | $source = $source->all(); |
45 | 45 | } |
46 | - if($meta->container){ |
|
46 | + if ($meta->container) { |
|
47 | 47 | $inputs[$meta->name] = $meta->container->make($source); |
48 | - }else{ |
|
48 | + }else { |
|
49 | 49 | $inputs[$meta->name] = $source; |
50 | 50 | } |
51 | - if($meta->validation){ |
|
51 | + if ($meta->validation) { |
|
52 | 52 | $vld->rule($meta->validation, $meta->name); |
53 | 53 | } |
54 | - }else{ |
|
54 | + }else { |
|
55 | 55 | $meta->isOptional or \PhpBoot\abort(new BadRequestHttpException("the parameter \"{$meta->source}\" is missing")); |
56 | 56 | $inputs[$meta->name] = $meta->default; |
57 | 57 | } |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | ); |
68 | 68 | |
69 | 69 | $pos = 0; |
70 | - foreach ($this->paramMetas as $meta){ |
|
71 | - if($meta->isPassedByReference){ |
|
70 | + foreach ($this->paramMetas as $meta) { |
|
71 | + if ($meta->isPassedByReference) { |
|
72 | 72 | $params[$pos] = &$reference[$meta->name]; |
73 | - }else{ |
|
73 | + }else { |
|
74 | 74 | $params[$pos] = $inputs[$meta->name]; |
75 | 75 | } |
76 | 76 | $pos++; |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | - public function getParamNames(){ |
|
82 | - return array_map(function($meta){return $meta->name;}, $this->paramMetas); |
|
81 | + public function getParamNames() { |
|
82 | + return array_map(function($meta) {return $meta->name; }, $this->paramMetas); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | 86 | * 获取参数列表 |
87 | 87 | * @return ParamMeta[] |
88 | 88 | */ |
89 | - public function getParamMetas(){ |
|
89 | + public function getParamMetas() { |
|
90 | 90 | return $this->paramMetas; |
91 | 91 | } |
92 | 92 | |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | * @param $name |
96 | 96 | * @return ParamMeta|null |
97 | 97 | */ |
98 | - public function getParamMeta($name){ |
|
99 | - foreach ($this->paramMetas as $meta){ |
|
100 | - if($meta->name == $name){ |
|
98 | + public function getParamMeta($name) { |
|
99 | + foreach ($this->paramMetas as $meta) { |
|
100 | + if ($meta->name == $name) { |
|
101 | 101 | return $meta; |
102 | 102 | } |
103 | 103 | } |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | } |
46 | 46 | if($meta->container){ |
47 | 47 | $inputs[$meta->name] = $meta->container->make($source); |
48 | - }else{ |
|
48 | + } else{ |
|
49 | 49 | $inputs[$meta->name] = $source; |
50 | 50 | } |
51 | 51 | if($meta->validation){ |
52 | 52 | $vld->rule($meta->validation, $meta->name); |
53 | 53 | } |
54 | - }else{ |
|
54 | + } else{ |
|
55 | 55 | $meta->isOptional or \PhpBoot\abort(new BadRequestHttpException("the parameter \"{$meta->source}\" is missing")); |
56 | 56 | $inputs[$meta->name] = $meta->default; |
57 | 57 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | foreach ($this->paramMetas as $meta){ |
71 | 71 | if($meta->isPassedByReference){ |
72 | 72 | $params[$pos] = &$reference[$meta->name]; |
73 | - }else{ |
|
73 | + } else{ |
|
74 | 74 | $params[$pos] = $inputs[$meta->name]; |
75 | 75 | } |
76 | 76 | $pos++; |
@@ -82,6 +82,9 @@ |
||
82 | 82 | return new DB($app, $connection); |
83 | 83 | } |
84 | 84 | |
85 | + /** |
|
86 | + * @param \PDO $connection |
|
87 | + */ |
|
85 | 88 | public function __construct(Application $app, $connection) |
86 | 89 | { |
87 | 90 | $this->app = $app; |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | */ |
68 | 68 | |
69 | 69 | static public function connect(Application $app, |
70 | - $dsn, |
|
71 | - $username, |
|
72 | - $password, |
|
73 | - $options = []) |
|
70 | + $dsn, |
|
71 | + $username, |
|
72 | + $password, |
|
73 | + $options = []) |
|
74 | 74 | { |
75 | 75 | $options += [ |
76 | 76 | \PDO::ATTR_ERRMODE =>\PDO::ERRMODE_EXCEPTION, |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | return $this->connection; |
166 | 166 | } |
167 | 167 | /** |
168 | - * Splice sql use raw string(without escaping) |
|
168 | + * Splice sql use raw string(without escaping) |
|
169 | 169 | * for example: |
170 | 170 | * where('time>?', 'now()') => " WHERE time > 'now()' " |
171 | 171 | * where('time>?', Sql::raw('now()')) => " WHERE time > now() " |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @author caoym <[email protected]> |
58 | 58 | */ |
59 | -class DB{ |
|
59 | +class DB { |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * DB constructor. |
@@ -97,18 +97,18 @@ discard block |
||
97 | 97 | * @param string $column0 |
98 | 98 | * @return \PhpBoot\DB\rules\select\FromRule |
99 | 99 | */ |
100 | - function select($column0=null, $_=null){ |
|
100 | + function select($column0 = null, $_ = null) { |
|
101 | 101 | $obj = new SelectRule(new Context($this->connection)); |
102 | - if($column0 == null){ |
|
102 | + if ($column0 == null) { |
|
103 | 103 | $args = ['*']; |
104 | - }elseif(is_array($column0)){ |
|
104 | + }elseif (is_array($column0)) { |
|
105 | 105 | $args = $column0; |
106 | - }else{ |
|
106 | + }else { |
|
107 | 107 | $args = func_get_args(); |
108 | 108 | } |
109 | - foreach ($args as &$arg){ |
|
109 | + foreach ($args as &$arg) { |
|
110 | 110 | $arg = DB::wrap($arg); |
111 | - if($arg == '*'){ |
|
111 | + if ($arg == '*') { |
|
112 | 112 | continue; |
113 | 113 | } |
114 | 114 | |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | * @param string $table |
141 | 141 | * @return \PhpBoot\DB\rules\basic\WhereRule |
142 | 142 | */ |
143 | - public function deleteFrom($table){ |
|
144 | - $obj = new DeleteRule(new Context($this->connection)); |
|
143 | + public function deleteFrom($table) { |
|
144 | + $obj = new DeleteRule(new Context($this->connection)); |
|
145 | 145 | return $obj->deleteFrom($table); |
146 | 146 | } |
147 | 147 | /** |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | * @param string $table |
150 | 150 | * @return \PhpBoot\DB\rules\replace\ValuesRule |
151 | 151 | */ |
152 | - public function replaceInto($table){ |
|
153 | - $obj = new ReplaceIntoRule(new Context($this->connection)); |
|
152 | + public function replaceInto($table) { |
|
153 | + $obj = new ReplaceIntoRule(new Context($this->connection)); |
|
154 | 154 | return $obj->replaceInto($table); |
155 | 155 | } |
156 | 156 | |
@@ -161,16 +161,16 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function transaction(callable $callback) |
163 | 163 | { |
164 | - if($this->inTransaction){ |
|
164 | + if ($this->inTransaction) { |
|
165 | 165 | return $callback($this); |
166 | 166 | } |
167 | 167 | $this->getConnection()->beginTransaction() or \PhpBoot\abort('beginTransaction failed'); |
168 | 168 | $this->inTransaction = true; |
169 | - try{ |
|
169 | + try { |
|
170 | 170 | $res = $callback($this); |
171 | 171 | $this->getConnection()->commit() or \PhpBoot\abort('commit failed'); |
172 | 172 | return $res; |
173 | - }catch (\Exception $e){ |
|
173 | + }catch (\Exception $e) { |
|
174 | 174 | $this->getConnection()->rollBack(); |
175 | 175 | Logger::warning('commit failed with '.get_class($e).' '.$e->getMessage()); |
176 | 176 | throw $e; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @param string $str |
192 | 192 | * @return Raw |
193 | 193 | */ |
194 | - static public function raw($str){ |
|
194 | + static public function raw($str) { |
|
195 | 195 | return new Raw($str); |
196 | 196 | } |
197 | 197 | static public function wrap($value) |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | if ($value === '*') { |
200 | 200 | return $value; |
201 | 201 | } |
202 | - if($value instanceof Raw){ |
|
202 | + if ($value instanceof Raw) { |
|
203 | 203 | return $value->get(); |
204 | 204 | } |
205 | 205 | return '`'.str_replace('`', '``', $value).'`'; |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | { |
213 | 213 | return $this->app; |
214 | 214 | } |
215 | - const ORDER_BY_ASC ='ASC'; |
|
216 | - const ORDER_BY_DESC ='DESC'; |
|
215 | + const ORDER_BY_ASC = 'ASC'; |
|
216 | + const ORDER_BY_DESC = 'DESC'; |
|
217 | 217 | |
218 | 218 | /** |
219 | 219 | * @var \PDO |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | $obj = new SelectRule(new Context($this->connection)); |
102 | 102 | if($column0 == null){ |
103 | 103 | $args = ['*']; |
104 | - }elseif(is_array($column0)){ |
|
104 | + } elseif(is_array($column0)){ |
|
105 | 105 | $args = $column0; |
106 | - }else{ |
|
106 | + } else{ |
|
107 | 107 | $args = func_get_args(); |
108 | 108 | } |
109 | 109 | foreach ($args as &$arg){ |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $res = $callback($this); |
171 | 171 | $this->getConnection()->commit() or \PhpBoot\abort('commit failed'); |
172 | 172 | return $res; |
173 | - }catch (\Exception $e){ |
|
173 | + } catch (\Exception $e){ |
|
174 | 174 | $this->getConnection()->rollBack(); |
175 | 175 | Logger::warning('commit failed with '.get_class($e).' '.$e->getMessage()); |
176 | 176 | throw $e; |
@@ -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 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param mixed $_ |
38 | 38 | * @return \PhpBoot\DB\rules\update\UpdateSetRule |
39 | 39 | */ |
40 | - public function set($expr, $_=null) { |
|
40 | + public function set($expr, $_ = null) { |
|
41 | 41 | $this->impl->set($this->context, $expr, array_slice(func_get_args(), 1)); |
42 | 42 | return $this; |
43 | 43 | } |
@@ -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']"], |