@@ -21,10 +21,10 @@ discard block |
||
| 21 | 21 | protected function analyse(array $context) |
| 22 | 22 | { |
| 23 | 23 | $replace = []; |
| 24 | - $attach = [] ; |
|
| 24 | + $attach = []; |
|
| 25 | 25 | foreach ($context as $key => $val) { |
| 26 | 26 | if ($this->isReplacedObj($val)) { |
| 27 | - $replace['{' . $key . '}'] = $val; |
|
| 27 | + $replace['{'.$key.'}'] = $val; |
|
| 28 | 28 | } else { |
| 29 | 29 | $attach[$key] = $val; |
| 30 | 30 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | protected function isReplacedObj($val) : bool |
| 36 | 36 | { |
| 37 | - return !is_array($val) && (!is_object($val) || method_exists($val, '__toString')) && ! $val instanceof \Throwable; |
|
| 37 | + return !is_array($val) && (!is_object($val) || method_exists($val, '__toString')) && !$val instanceof \Throwable; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public function interpolate(string $message, array $context, array $attribute) |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | list($attach, $replace) = $this->analyse($context); |
| 43 | 43 | $attribute = array_merge($this->attribute, $attribute); |
| 44 | 44 | foreach ($attribute as $key => $val) { |
| 45 | - $replace['%' . $key . '%'] = $val; |
|
| 45 | + $replace['%'.$key.'%'] = $val; |
|
| 46 | 46 | } |
| 47 | 47 | $message = strtr($message, $replace); |
| 48 | 48 | $attachInfo = ''; |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | * @param boolean $ignoreCase |
| 48 | 48 | * @return array|null |
| 49 | 49 | */ |
| 50 | - public function match(string $url, bool $ignoreCase = true):?array |
|
| 50 | + public function match(string $url, bool $ignoreCase = true): ?array |
|
| 51 | 51 | { |
| 52 | - $match = '#^'. $this->match.'$#'. ($ignoreCase?'i':''); |
|
| 52 | + $match = '#^'.$this->match.'$#'.($ignoreCase ? 'i' : ''); |
|
| 53 | 53 | $parameter = []; |
| 54 | 54 | if (preg_match($match, $url, $parameter, PREG_UNMATCHED_AS_NULL) > 0) { |
| 55 | 55 | return array_slice($parameter, 1); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | return $parameters; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - public function getParameter(string $name):?Parameter |
|
| 81 | + public function getParameter(string $name): ?Parameter |
|
| 82 | 82 | { |
| 83 | 83 | foreach ($this->parameter as $parameter) { |
| 84 | 84 | if ($parameter->getIndexName() === $name) { |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @param integer $index |
| 129 | 129 | * @return \suda\framework\route\uri\parameter\Parameter|null |
| 130 | 130 | */ |
| 131 | - public function getParameterByIndex(int $index):?Parameter |
|
| 131 | + public function getParameterByIndex(int $index): ?Parameter |
|
| 132 | 132 | { |
| 133 | 133 | foreach ($this->parameter as $parameter) { |
| 134 | 134 | if ($parameter->getIndex() === $index) { |
@@ -20,10 +20,10 @@ |
||
| 20 | 20 | protected $tag = [ |
| 21 | 21 | 'raw' => ['{{!', '}}', '<?php echo $code; ?>'], |
| 22 | 22 | 'comment' => ['{--', '--}', '<?php /* $code */ ?>'], |
| 23 | - 'echo' => [ '{{', '}}', '<?php echo htmlspecialchars($this->application->_($code), ENT_SUBSTITUTE | ENT_QUOTES | ENT_HTML5); ?>' ], |
|
| 23 | + 'echo' => ['{{', '}}', '<?php echo htmlspecialchars($this->application->_($code), ENT_SUBSTITUTE | ENT_QUOTES | ENT_HTML5); ?>'], |
|
| 24 | 24 | 'string' => ['{=', '}', '<?php echo htmlspecialchars($this->application->_("$code"), ENT_SUBSTITUTE | ENT_QUOTES | ENT_HTML5); ?>'], |
| 25 | - 'raw-string' => ['@{', '}', '<?php echo htmlspecialchars($code, ENT_SUBSTITUTE | ENT_QUOTES | ENT_HTML5); ?>' ], |
|
| 26 | - 'event' => ['{:', '}', '<?php $this->application->event()->exec("$code", [$this]); ?>' ], |
|
| 25 | + 'raw-string' => ['@{', '}', '<?php echo htmlspecialchars($code, ENT_SUBSTITUTE | ENT_QUOTES | ENT_HTML5); ?>'], |
|
| 26 | + 'event' => ['{:', '}', '<?php $this->application->event()->exec("$code", [$this]); ?>'], |
|
| 27 | 27 | ]; |
| 28 | 28 | |
| 29 | 29 | public function __construct() |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * |
| 12 | 12 | * @var array |
| 13 | 13 | */ |
| 14 | - private $locales=[]; |
|
| 14 | + private $locales = []; |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * 包含本地化语言数组 |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public static function format(string $string, array $param) |
| 51 | 51 | { |
| 52 | - return preg_replace_callback('/(?<!\$)\$(\{)?(\d+|\w+?\b)(?(1)\})/', function ($match) use ($param) { |
|
| 52 | + return preg_replace_callback('/(?<!\$)\$(\{)?(\d+|\w+?\b)(?(1)\})/', function($match) use ($param) { |
|
| 53 | 53 | $key = $match[2]; |
| 54 | 54 | if (array_key_exists($key, $param)) { |
| 55 | 55 | return strval($param[$key]); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @param array|\suda\framework\Config $extra |
| 113 | 113 | * @return array|null |
| 114 | 114 | */ |
| 115 | - public static function loadConfig(string $path, $extra = []):?array |
|
| 115 | + public static function loadConfig(string $path, $extra = []): ?array |
|
| 116 | 116 | { |
| 117 | 117 | if (!file_exists($path)) { |
| 118 | 118 | $path = PathResolver::resolve($path); |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | if ($path) { |
| 124 | 124 | $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION)); |
| 125 | - if (in_array($ext, ['yaml','yml','json','php','ini'])) { |
|
| 125 | + if (in_array($ext, ['yaml', 'yml', 'json', 'php', 'ini'])) { |
|
| 126 | 126 | return ContentLoader::{'load'.ucfirst($ext)}($path, $extra); |
| 127 | 127 | } |
| 128 | 128 | return ContentLoader::loadJson($path, $extra); |
@@ -120,7 +120,7 @@ |
||
| 120 | 120 | |
| 121 | 121 | protected function parseStatic($content) |
| 122 | 122 | { |
| 123 | - $content = strlen(trim($content)) === 0 ?'()':$content; |
|
| 123 | + $content = strlen(trim($content)) === 0 ? '()' : $content; |
|
| 124 | 124 | return '<?php echo $this->getStaticPrefix'.$content.'; ?>'; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | $table = $this->connection->rawTableName($this->name); |
| 71 | 71 | $sql = "CREATE TABLE IF NOT EXISTS `{$table}` (\r\n\t"; |
| 72 | 72 | $sql .= implode(",\r\n\t", array_filter($content, 'strlen')); |
| 73 | - $auto = null === $this->auto?'':'AUTO_INCREMENT='.$this->auto; |
|
| 74 | - $collate = null === $this->collate?'':'COLLATE '.$this->collate; |
|
| 73 | + $auto = null === $this->auto ? '' : 'AUTO_INCREMENT='.$this->auto; |
|
| 74 | + $collate = null === $this->collate ? '' : 'COLLATE '.$this->collate; |
|
| 75 | 75 | $sql .= "\r\n) ENGINE={$this->engine} {$collate} {$auto} DEFAULT CHARSET={$this->charset};"; |
| 76 | 76 | return $sql; |
| 77 | 77 | } |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | protected function createField(Field $field) |
| 137 | 137 | { |
| 138 | - $type = $field->getLength()? strtoupper($field->getValueType()).'('.$field->getLength().')':strtoupper($field->getValueType()); |
|
| 139 | - $auto = $field->getAuto() ?'AUTO_INCREMENT':''; |
|
| 140 | - $null = $field->isNullable() ?'NULL':'NOT NULL'; |
|
| 141 | - $attr = $field->getAttribute() ?strtoupper($field->getAttribute()):''; |
|
| 142 | - $comment = $field->getComment() ?('COMMENT \''.addcslashes($field->getComment(), '\'').'\''):''; |
|
| 138 | + $type = $field->getLength() ? strtoupper($field->getValueType()).'('.$field->getLength().')' : strtoupper($field->getValueType()); |
|
| 139 | + $auto = $field->getAuto() ? 'AUTO_INCREMENT' : ''; |
|
| 140 | + $null = $field->isNullable() ? 'NULL' : 'NOT NULL'; |
|
| 141 | + $attr = $field->getAttribute() ?strtoupper($field->getAttribute()) : ''; |
|
| 142 | + $comment = $field->getComment() ? ('COMMENT \''.addcslashes($field->getComment(), '\'').'\'') : ''; |
|
| 143 | 143 | // default设置 |
| 144 | 144 | if ($field->hasDefault()) { |
| 145 | 145 | if (null === $field->getDefault()) { |
@@ -48,12 +48,12 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function __construct($object, ?array $constructParameter = null, string $method, array $parameter = []) |
| 50 | 50 | { |
| 51 | - $this->object = is_object($object)? $object: $this->getPHPClassName($object); |
|
| 51 | + $this->object = is_object($object) ? $object : $this->getPHPClassName($object); |
|
| 52 | 52 | $this->constructParameter = $constructParameter; |
| 53 | 53 | $this->method = $method; |
| 54 | 54 | $this->parameter = $parameter; |
| 55 | 55 | $static = $this->isStatic() ? '->' : '::'; |
| 56 | - $name = \is_object($object)? \get_class($object) : $object; |
|
| 56 | + $name = \is_object($object) ? \get_class($object) : $object; |
|
| 57 | 57 | $this->name = $name.$static.$method; |
| 58 | 58 | } |
| 59 | 59 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * @return object|null 动态类可获取 |
| 64 | 64 | */ |
| 65 | - public function getObjectInstance():?object |
|
| 65 | + public function getObjectInstance(): ?object |
|
| 66 | 66 | { |
| 67 | 67 | if (\is_object($this->object)) { |
| 68 | 68 | return $this->object; |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | $this->routes = new RouteCollection; |
| 44 | 44 | $this->runnable = []; |
| 45 | - $this->default = new Runnable([__CLASS__ , 'defaultResponse']); |
|
| 45 | + $this->default = new Runnable([__CLASS__, 'defaultResponse']); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | * @param boolean $allowQuery |
| 290 | 290 | * @return string|null |
| 291 | 291 | */ |
| 292 | - public function create(string $name, array $parameter, bool $allowQuery = true):?string |
|
| 292 | + public function create(string $name, array $parameter, bool $allowQuery = true): ?string |
|
| 293 | 293 | { |
| 294 | 294 | if ($matcher = $this->routes->get($name)) { |
| 295 | 295 | return UriMatcher::buildUri($matcher->getMatcher(), $parameter, $allowQuery); |