@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $handler->setMapping($params[0], $return); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - }elseif($ann->parent->name == 'param'){ |
|
| 47 | + } elseif($ann->parent->name == 'param'){ |
|
| 48 | 48 | list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description); |
| 49 | 49 | |
| 50 | 50 | $paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | ContainerFactory::create($entityBuilder, $paramMeta->type) |
| 60 | 60 | ) |
| 61 | 61 | ); |
| 62 | - }else{ |
|
| 62 | + } else{ |
|
| 63 | 63 | $paramMeta->source = $params[0]; |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -21,15 +21,15 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function __invoke(ControllerContainer $container, $ann, EntityContainerBuilder $entityBuilder) |
| 23 | 23 | { |
| 24 | - if(!$ann->parent || !$ann->parent->parent){ |
|
| 24 | + if (!$ann->parent || !$ann->parent->parent) { |
|
| 25 | 25 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent param/return"); |
| 26 | 26 | return; |
| 27 | 27 | } |
| 28 | 28 | $target = $ann->parent->parent->name; |
| 29 | 29 | $route = $container->getRoute($target); |
| 30 | - if(!$route){ |
|
| 30 | + if (!$route) { |
|
| 31 | 31 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent param/return"); |
| 32 | - return ; |
|
| 32 | + return; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $params = new AnnotationParams($ann->description, 2); |
@@ -38,20 +38,20 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | $handler = $route->getResponseHandler(); |
| 40 | 40 | |
| 41 | - if ($ann->parent->name == 'return'){ |
|
| 41 | + if ($ann->parent->name == 'return') { |
|
| 42 | 42 | list($target, $return) = $handler->getMappingBySource('return'); |
| 43 | - if($return){ |
|
| 43 | + if ($return) { |
|
| 44 | 44 | $handler->eraseMapping($target); |
| 45 | 45 | $handler->setMapping($params[0], $return); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - }elseif($ann->parent->name == 'param'){ |
|
| 48 | + }elseif ($ann->parent->name == 'param') { |
|
| 49 | 49 | list($paramType, $paramName, $paramDoc) = ParamAnnotationHandler::getParamInfo($ann->parent->description); |
| 50 | 50 | |
| 51 | 51 | $paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
| 52 | - if($paramMeta->isPassedByReference){ |
|
| 52 | + if ($paramMeta->isPassedByReference) { |
|
| 53 | 53 | list($target, $ori) = $handler->getMappingBySource('params.'.$paramName); |
| 54 | - if($ori){ |
|
| 54 | + if ($ori) { |
|
| 55 | 55 | $handler->eraseMapping($target); |
| 56 | 56 | } |
| 57 | 57 | //输出绑定 |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | ContainerFactory::create($entityBuilder, $paramMeta->type) |
| 64 | 64 | ) |
| 65 | 65 | ); |
| 66 | - }else{ |
|
| 66 | + }else { |
|
| 67 | 67 | $paramMeta->source = $params[0]; |
| 68 | 68 | } |
| 69 | 69 | } |
@@ -19,15 +19,15 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public function __invoke(ControllerContainer $container, $ann) |
| 21 | 21 | { |
| 22 | - if(!$ann->parent){ |
|
| 22 | + if (!$ann->parent) { |
|
| 23 | 23 | //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent route"); |
| 24 | 24 | return; |
| 25 | 25 | } |
| 26 | 26 | $target = $ann->parent->name; |
| 27 | 27 | $route = $container->getRoute($target); |
| 28 | - if(!$route){ |
|
| 28 | + if (!$route) { |
|
| 29 | 29 | //Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent route"); |
| 30 | - return ; |
|
| 30 | + return; |
|
| 31 | 31 | } |
| 32 | 32 | $params = new AnnotationParams($ann->description, 2); |
| 33 | 33 | count($params)>0 or \PhpBoot\abort(new AnnotationSyntaxException("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require at least one param, {$params->count()} given")); |
@@ -18,29 +18,29 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | public function __invoke(ControllerContainer $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 | $route = $container->getRoute($target); |
| 27 | - if(!$route){ |
|
| 27 | + if (!$route) { |
|
| 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 = $route->getRequestHandler()->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)) { |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | $paramMeta = $route->getRequestHandler()->getParamMeta($paramName); |
| 39 | 39 | if($params->count()>1){ |
| 40 | 40 | $paramMeta->validation = [$params[0], $params[1]]; |
| 41 | - }else{ |
|
| 41 | + } else{ |
|
| 42 | 42 | $paramMeta->validation = $params[0]; |
| 43 | 43 | if($paramMeta->validation) { |
| 44 | 44 | $v = new Validator(); |
@@ -18,15 +18,15 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | public function __invoke(ControllerContainer $container, $ann) |
| 20 | 20 | { |
| 21 | - if(!$ann->parent){ |
|
| 21 | + if (!$ann->parent) { |
|
| 22 | 22 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()} should be used with parent route"); |
| 23 | 23 | return; |
| 24 | 24 | } |
| 25 | 25 | $target = $ann->parent->name; |
| 26 | 26 | $route = $container->getRoute($target); |
| 27 | - if(!$route){ |
|
| 27 | + if (!$route) { |
|
| 28 | 28 | Logger::debug("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target should be used with parent route"); |
| 29 | - return ; |
|
| 29 | + return; |
|
| 30 | 30 | } |
| 31 | 31 | $params = new AnnotationParams($ann->description, 2); |
| 32 | 32 | count($params)>0 or \PhpBoot\abort("The annotation \"@{$ann->name} {$ann->description}\" of {$container->getClassName()}::$target require at least one param, 0 given"); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function getRoute($actionName) |
| 50 | 50 | { |
| 51 | - if (array_key_exists($actionName, $this->routes)){ |
|
| 51 | + if (array_key_exists($actionName, $this->routes)) { |
|
| 52 | 52 | return $this->routes[$actionName]; |
| 53 | 53 | } |
| 54 | 54 | return false; |
@@ -170,16 +170,16 @@ discard block |
||
| 170 | 170 | /** |
| 171 | 171 | * @var Route[] |
| 172 | 172 | */ |
| 173 | - private $routes=[]; |
|
| 173 | + private $routes = []; |
|
| 174 | 174 | |
| 175 | 175 | /** |
| 176 | 176 | * @var string |
| 177 | 177 | */ |
| 178 | - private $description=''; |
|
| 178 | + private $description = ''; |
|
| 179 | 179 | /** |
| 180 | 180 | * @var string |
| 181 | 181 | */ |
| 182 | - private $summary=''; |
|
| 182 | + private $summary = ''; |
|
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * @var string |
@@ -8,12 +8,12 @@ discard block |
||
| 8 | 8 | class Route |
| 9 | 9 | { |
| 10 | 10 | public function __construct( |
| 11 | - $method='', |
|
| 12 | - $uri='', |
|
| 13 | - RequestHandler $requestHandler=null, |
|
| 14 | - ResponseHandler $responseHandler=null, |
|
| 15 | - ExceptionHandler $exceptionHandler=null, |
|
| 16 | - $hooks=[], |
|
| 11 | + $method = '', |
|
| 12 | + $uri = '', |
|
| 13 | + RequestHandler $requestHandler = null, |
|
| 14 | + ResponseHandler $responseHandler = null, |
|
| 15 | + ExceptionHandler $exceptionHandler = null, |
|
| 16 | + $hooks = [], |
|
| 17 | 17 | $summary = '', |
| 18 | 18 | $description = '') |
| 19 | 19 | { |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $res = call_user_func_array($function, $params); |
| 51 | 51 | return $this->responseHandler->handle($app, $res, $reference); |
| 52 | 52 | }; |
| 53 | - foreach (array_reverse($this->hooks) as $hookName){ |
|
| 53 | + foreach (array_reverse($this->hooks) as $hookName) { |
|
| 54 | 54 | $next = function($request)use($app, $hookName, $next){ |
| 55 | 55 | $hook = $app->get($hookName); |
| 56 | 56 | /**@var $hook HookInterface*/ |
@@ -262,17 +262,17 @@ discard block |
||
| 262 | 262 | /** |
| 263 | 263 | * @var string |
| 264 | 264 | */ |
| 265 | - private $description=''; |
|
| 265 | + private $description = ''; |
|
| 266 | 266 | |
| 267 | 267 | /** |
| 268 | 268 | * hook class names |
| 269 | 269 | * @var string[] |
| 270 | 270 | */ |
| 271 | - private $hooks=[]; |
|
| 271 | + private $hooks = []; |
|
| 272 | 272 | |
| 273 | 273 | /** |
| 274 | 274 | * @var string[] |
| 275 | 275 | */ |
| 276 | - private $pathParams =[]; |
|
| 276 | + private $pathParams = []; |
|
| 277 | 277 | |
| 278 | 278 | } |
| 279 | 279 | \ No newline at end of file |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | class CheckableCache |
| 11 | 11 | { |
| 12 | - function __construct(Cache $impl){ |
|
| 12 | + function __construct(Cache $impl) { |
|
| 13 | 13 | $this->impl = $impl; |
| 14 | 14 | } |
| 15 | 15 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @param bool $deleteExpiredData |
| 44 | 44 | * @return mixed |
| 45 | 45 | */ |
| 46 | - public function get($name, $default = null, &$expiredData=null, $deleteExpiredData=true) |
|
| 46 | + public function get($name, $default = null, &$expiredData = null, $deleteExpiredData = true) |
|
| 47 | 47 | { |
| 48 | 48 | $expiredData = null; |
| 49 | 49 | $res = $this->impl->fetch($name); |
@@ -52,18 +52,18 @@ discard block |
||
| 52 | 52 | // 如果指定了checker, ttl代表每次检查的间隔时间, 0表示每次get都需要经过checker检查 |
| 53 | 53 | // 如果没有指定checker, ttl表示缓存过期时间, 为0表示永不过期 |
| 54 | 54 | if ($checker !== null) { |
| 55 | - if ($ttl == 0 || ($createdTime + $ttl < time())) { |
|
| 55 | + if ($ttl == 0 || ($createdTime + $ttl<time())) { |
|
| 56 | 56 | $valid = $checker($data, $createdTime); |
| 57 | - if(!$valid){ |
|
| 57 | + if (!$valid) { |
|
| 58 | 58 | $expiredData = $data; |
| 59 | - if($deleteExpiredData){ |
|
| 59 | + if ($deleteExpiredData) { |
|
| 60 | 60 | $this->impl->delete($name); |
| 61 | 61 | } |
| 62 | 62 | return $default; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | } |
| 66 | - }else if ($ttl != 0 && ($createdTime + $ttl < time())) { |
|
| 66 | + }else if ($ttl != 0 && ($createdTime + $ttl<time())) { |
|
| 67 | 67 | $this->impl->delete($name); |
| 68 | 68 | return $default; |
| 69 | 69 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * 删除 |
| 76 | 76 | * @param string $name |
| 77 | 77 | */ |
| 78 | - public function del($name){ |
|
| 78 | + public function del($name) { |
|
| 79 | 79 | return $this->impl->delete($name); |
| 80 | 80 | } |
| 81 | 81 | public function getImpl() |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | } |
| 66 | - }else if ($ttl != 0 && ($createdTime + $ttl < time())) { |
|
| 66 | + } else if ($ttl != 0 && ($createdTime + $ttl < time())) { |
|
| 67 | 67 | $this->impl->delete($name); |
| 68 | 68 | return $default; |
| 69 | 69 | } |
@@ -10,25 +10,25 @@ discard block |
||
| 10 | 10 | /** |
| 11 | 11 | * @param string|array $fileName 文件的绝对路径 |
| 12 | 12 | */ |
| 13 | - function __construct($fileName){ |
|
| 13 | + function __construct($fileName) { |
|
| 14 | 14 | $fileNames = array(); |
| 15 | - if(is_string($fileName)){ |
|
| 16 | - $fileNames[]=$fileName; |
|
| 17 | - }else{ |
|
| 15 | + if (is_string($fileName)) { |
|
| 16 | + $fileNames[] = $fileName; |
|
| 17 | + }else { |
|
| 18 | 18 | is_array($fileName) or \PhpBoot\abort(new \InvalidArgumentException("string or array is required by param 0")); |
| 19 | 19 | $fileNames = $fileName; |
| 20 | 20 | } |
| 21 | - foreach ($fileNames as $fileName){ |
|
| 22 | - if(is_file($fileName)){ |
|
| 21 | + foreach ($fileNames as $fileName) { |
|
| 22 | + if (is_file($fileName)) { |
|
| 23 | 23 | $this->fileName[$fileName] = @filemtime($fileName); |
| 24 | 24 | }else { |
| 25 | 25 | $this->fileName[$fileName] = @filemtime($fileName); |
| 26 | - if(!is_dir($fileName)){ |
|
| 26 | + if (!is_dir($fileName)) { |
|
| 27 | 27 | continue; |
| 28 | 28 | } |
| 29 | 29 | $files = @dir($fileName) or \PhpBoot\abort("open dir $fileName failed"); |
| 30 | - while (!!($file = $files->read())){ |
|
| 31 | - if($file == '.' || $file == '..') { |
|
| 30 | + while (!!($file = $files->read())) { |
|
| 31 | + if ($file == '.' || $file == '..') { |
|
| 32 | 32 | continue; |
| 33 | 33 | } |
| 34 | 34 | $this->fileName[$fileName.'/'.$file] = @filemtime($fileName.'/'.$file); |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | * @param int $createdTime |
| 44 | 44 | * @return boolean |
| 45 | 45 | */ |
| 46 | - public function __invoke($data, $createdTime){ |
|
| 47 | - foreach ($this->fileName as $name => $time){ |
|
| 48 | - if(@filemtime($name) != $time){ |
|
| 46 | + public function __invoke($data, $createdTime) { |
|
| 47 | + foreach ($this->fileName as $name => $time) { |
|
| 48 | + if (@filemtime($name) != $time) { |
|
| 49 | 49 | return false; |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | return true; |
| 53 | 53 | } |
| 54 | - private $fileName=[]; //文件全路径 |
|
| 54 | + private $fileName = []; //文件全路径 |
|
| 55 | 55 | } |
@@ -14,14 +14,14 @@ |
||
| 14 | 14 | $fileNames = array(); |
| 15 | 15 | if(is_string($fileName)){ |
| 16 | 16 | $fileNames[]=$fileName; |
| 17 | - }else{ |
|
| 17 | + } else{ |
|
| 18 | 18 | is_array($fileName) or \PhpBoot\abort(new \InvalidArgumentException("string or array is required by param 0")); |
| 19 | 19 | $fileNames = $fileName; |
| 20 | 20 | } |
| 21 | 21 | foreach ($fileNames as $fileName){ |
| 22 | 22 | if(is_file($fileName)){ |
| 23 | 23 | $this->fileName[$fileName] = @filemtime($fileName); |
| 24 | - }else { |
|
| 24 | + } else { |
|
| 25 | 25 | $this->fileName[$fileName] = @filemtime($fileName); |
| 26 | 26 | if(!is_dir($fileName)){ |
| 27 | 27 | continue; |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | $line = $e->getLine(); |
| 36 | 36 | } |
| 37 | 37 | if($level){ |
| 38 | - Logger::$level($message, $context +['@file'=>$file, '@line'=>$line]); |
|
| 38 | + Logger::$level($message, $context +['@file'=>$file, '@line'=>$line]); |
|
| 39 | 39 | } |
| 40 | 40 | throw $e; |
| 41 | 41 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | if($error instanceof \Exception){ |
| 22 | 22 | $e = $error; |
| 23 | 23 | $message = "exception '".get_class($error)."' with message {$error->getMessage()}"; |
| 24 | - }else{ |
|
| 24 | + } else{ |
|
| 25 | 25 | $e = new \RuntimeException($error); |
| 26 | 26 | $message = $error; |
| 27 | 27 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | if($e->getFile() == __FILE__){ |
| 31 | 31 | $file = $trace[0]['file']; |
| 32 | 32 | $line = $trace[0]['line']; |
| 33 | - }else{ |
|
| 33 | + } else{ |
|
| 34 | 34 | $file = $e->getFile(); |
| 35 | 35 | $line = $e->getLine(); |
| 36 | 36 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | { |
| 54 | 54 | if(is_object($entity)){ |
| 55 | 55 | return $db->getApp()->make(ModelWithObject::class, ['db'=>$db, 'entity'=>$entity]); |
| 56 | - }else{ |
|
| 56 | + } else{ |
|
| 57 | 57 | return $db->getApp()->make(ModelWithClass::class, ['db'=>$db, 'entityName'=>$entity]); |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use PhpBoot\ORM\ModelWithObject; |
| 6 | 6 | use PhpBoot\Utils\Logger; |
| 7 | 7 | |
| 8 | -if (! function_exists('PhpBoot\abort')) { |
|
| 8 | +if (!function_exists('PhpBoot\abort')) { |
|
| 9 | 9 | /** |
| 10 | 10 | * 抛出异常, 并记录日志 |
| 11 | 11 | * @param string|\Exception $error |
@@ -13,29 +13,29 @@ discard block |
||
| 13 | 13 | * @param string $level "error"|"warning"|"info"|"debug"|null |
| 14 | 14 | * @throws \Exception |
| 15 | 15 | */ |
| 16 | - function abort($error = '', $context=[], $level='warning') |
|
| 16 | + function abort($error = '', $context = [], $level = 'warning') |
|
| 17 | 17 | { |
| 18 | - if(is_object($context)){ |
|
| 18 | + if (is_object($context)) { |
|
| 19 | 19 | $context = get_object_vars($context); |
| 20 | 20 | } |
| 21 | - if($error instanceof \Exception){ |
|
| 21 | + if ($error instanceof \Exception) { |
|
| 22 | 22 | $e = $error; |
| 23 | 23 | $message = "exception '".get_class($error)."' with message {$error->getMessage()}"; |
| 24 | - }else{ |
|
| 24 | + }else { |
|
| 25 | 25 | $e = new \RuntimeException($error); |
| 26 | 26 | $message = $error; |
| 27 | 27 | } |
| 28 | 28 | $trace = $e->getTrace(); |
| 29 | 29 | |
| 30 | - if($e->getFile() == __FILE__){ |
|
| 30 | + if ($e->getFile() == __FILE__) { |
|
| 31 | 31 | $file = $trace[0]['file']; |
| 32 | 32 | $line = $trace[0]['line']; |
| 33 | - }else{ |
|
| 33 | + }else { |
|
| 34 | 34 | $file = $e->getFile(); |
| 35 | 35 | $line = $e->getLine(); |
| 36 | 36 | } |
| 37 | - if($level){ |
|
| 38 | - Logger::$level($message, $context +['@file'=>$file, '@line'=>$line]); |
|
| 37 | + if ($level) { |
|
| 38 | + Logger::$level($message, $context + ['@file'=>$file, '@line'=>$line]); |
|
| 39 | 39 | } |
| 40 | 40 | throw $e; |
| 41 | 41 | } |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | function models(DB $db, $entity) |
| 63 | 63 | { |
| 64 | - if(is_object($entity)){ |
|
| 64 | + if (is_object($entity)) { |
|
| 65 | 65 | return $db->getApp()->make(ModelWithObject::class, ['db'=>$db, 'entity'=>$entity]); |
| 66 | - }else{ |
|
| 66 | + }else { |
|
| 67 | 67 | return $db->getApp()->make(ModelWithClass::class, ['db'=>$db, 'entityName'=>$entity]); |
| 68 | 68 | } |
| 69 | 69 | } |