@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @param string $path |
| 81 | 81 | * @return \suda\application\Module|null |
| 82 | 82 | */ |
| 83 | - public function guess(string $path):?Module |
|
| 83 | + public function guess(string $path): ?Module |
|
| 84 | 84 | { |
| 85 | 85 | foreach ($this->module as $module) { |
| 86 | 86 | if (FileSystem::isOverflowPath($module->getPath(), $path) === false) { |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @throws ApplicationException |
| 113 | 113 | * @return Module|null |
| 114 | 114 | */ |
| 115 | - public function get(string $name):?Module |
|
| 115 | + public function get(string $name): ?Module |
|
| 116 | 116 | { |
| 117 | 117 | $full = $this->getFullName($name); |
| 118 | 118 | return $this->module[$full]; |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | if (array_key_exists($version, $this->knownsFullName[$name])) { |
| 197 | 197 | return $this->knownsFullName[$name][$version]; |
| 198 | 198 | } |
| 199 | - return $hasVersion?$name.':'.$version:end($this->knownsFullName[$name]); |
|
| 199 | + return $hasVersion ? $name.':'.$version : end($this->knownsFullName[$name]); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | protected function getLikeName(string $name):string |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param string|null $default |
| 26 | 26 | * @return string|null |
| 27 | 27 | */ |
| 28 | - public function getUrl(Request $request, string $name, array $parameter = [], bool $allowQuery = true, ?string $default = null, ?string $group = null):?string |
|
| 28 | + public function getUrl(Request $request, string $name, array $parameter = [], bool $allowQuery = true, ?string $default = null, ?string $group = null): ?string |
|
| 29 | 29 | { |
| 30 | 30 | $group = $group ?? $request->getAttribute('group'); |
| 31 | 31 | $default = $default ?? $request->getAttribute('module'); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | protected function getUrlIndex(Request $request):string |
| 43 | 43 | { |
| 44 | - $indexs = $this->conf('indexs') ?? [ 'index.php' ]; |
|
| 44 | + $indexs = $this->conf('indexs') ?? ['index.php']; |
|
| 45 | 45 | $index = ltrim($request->getIndex(), '/'); |
| 46 | 46 | if (!in_array($index, $indexs)) { |
| 47 | 47 | return $request->getIndex(); |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | public function getUribase(Request $request, bool $beautify = true):string { |
| 145 | 145 | $index = $beautify ? $this->getUrlIndex($request) : $request->getIndex(); |
| 146 | - return $request->getUribase() . $index; |
|
| 146 | + return $request->getUribase().$index; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,6 +154,6 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | protected function getRouteGroupPrefix(?string $group):string |
| 156 | 156 | { |
| 157 | - return $group === null || $group === 'default' ? '': '@'. $group; |
|
| 157 | + return $group === null || $group === 'default' ? '' : '@'.$group; |
|
| 158 | 158 | } |
| 159 | 159 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public function __construct($file) |
| 39 | 39 | { |
| 40 | - $this->file = $file instanceof SplFileObject? $file : new SplFileObject($file); |
|
| 40 | + $this->file = $file instanceof SplFileObject ? $file : new SplFileObject($file); |
|
| 41 | 41 | $this->mime = MimeType::getMimeType($this->file->getExtension()); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | protected function sendMultipleRangePart(Response $response, array $range) |
| 130 | 130 | { |
| 131 | 131 | $response->write('Content-Type: '.$this->mime."\r\n"); |
| 132 | - $response->write('Content-Range: '.$this->getRangeHeader($range) ."\r\n\r\n"); |
|
| 132 | + $response->write('Content-Range: '.$this->getRangeHeader($range)."\r\n\r\n"); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * @param string $range |
| 189 | 189 | * @return array |
| 190 | 190 | */ |
| 191 | - protected function parseRange(string $range):?array |
|
| 191 | + protected function parseRange(string $range): ?array |
|
| 192 | 192 | { |
| 193 | 193 | $range = trim($range); |
| 194 | 194 | if (strrpos($range, '-') === strlen($range) - 1) { |
@@ -200,9 +200,9 @@ discard block |
||
| 200 | 200 | list($start, $end) = explode('-', $range, 2); |
| 201 | 201 | $length = intval($end - $start); |
| 202 | 202 | if ($length <= 0) { |
| 203 | - return ['start' => intval($start) , 'end' => $this->file->getSize() - 1 ]; |
|
| 203 | + return ['start' => intval($start), 'end' => $this->file->getSize() - 1]; |
|
| 204 | 204 | } |
| 205 | - return ['start' => intval($start) , 'end' => intval($end) ]; |
|
| 205 | + return ['start' => intval($start), 'end' => intval($end)]; |
|
| 206 | 206 | } |
| 207 | 207 | return null; |
| 208 | 208 | } |
@@ -59,7 +59,7 @@ |
||
| 59 | 59 | * @return DataAccess |
| 60 | 60 | * @throws ReflectionException |
| 61 | 61 | */ |
| 62 | - public static function new(string $object, ?Middleware $middleware = null):DataAccess |
|
| 62 | + public static function new(string $object, ?Middleware $middleware = null) : DataAccess |
|
| 63 | 63 | { |
| 64 | 64 | return new self($object, $middleware); |
| 65 | 65 | } |
@@ -33,10 +33,10 @@ |
||
| 33 | 33 | $status = $result ? 'OK' : 'Err'; |
| 34 | 34 | if ($result) { |
| 35 | 35 | $effect = $statement->getStatement()->rowCount(); |
| 36 | - $this->debug->info('query ['.$status.'] '.$query.' '. number_format($timeSpend, 5).'s and effect '. $effect . ' rows'); |
|
| 36 | + $this->debug->info('query ['.$status.'] '.$query.' '.number_format($timeSpend, 5).'s and effect '.$effect.' rows'); |
|
| 37 | 37 | } else { |
| 38 | - $this->debug->error('query ['.$status.'] '.$query.' '. number_format($timeSpend, 5).'s'); |
|
| 39 | - $this->debug->error('query ['.$status.'] '. implode(':', $statement->getStatement()->errorInfo())); |
|
| 38 | + $this->debug->error('query ['.$status.'] '.$query.' '.number_format($timeSpend, 5).'s'); |
|
| 39 | + $this->debug->error('query ['.$status.'] '.implode(':', $statement->getStatement()->errorInfo())); |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | protected static function fixConfig(Application $application, ?string $module, array $config) |
| 45 | 45 | { |
| 46 | 46 | if (!array_key_exists('assets-prefix', $config)) { |
| 47 | - $config['assets-prefix'] = defined('SUDA_ASSETS') ? constant('SUDA_ASSETS'): 'assets'; |
|
| 47 | + $config['assets-prefix'] = defined('SUDA_ASSETS') ? constant('SUDA_ASSETS') : 'assets'; |
|
| 48 | 48 | } |
| 49 | 49 | if (!array_key_exists('static', $config)) { |
| 50 | 50 | $config['static'] = 'static'; |
| 51 | 51 | } |
| 52 | 52 | if (!array_key_exists('assets-path', $config)) { |
| 53 | - $config['assets-path'] = SUDA_PUBLIC. '/'.$config['assets-prefix']; |
|
| 53 | + $config['assets-path'] = SUDA_PUBLIC.'/'.$config['assets-prefix']; |
|
| 54 | 54 | } |
| 55 | 55 | if (!array_key_exists('static-name', $config)) { |
| 56 | 56 | $config['uri-name'] = static::getSafeUriName($application, $module); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | { |
| 113 | 113 | $assetRoot = static::getAssetRoot($application, $module); |
| 114 | 114 | if (in_array($request->getIndex(), $application->conf('index', ['/index.php']))) { |
| 115 | - $name = static::writableAssets($application, $module) ? dirname($request->getIndex()):$request->getIndex(); |
|
| 115 | + $name = static::writableAssets($application, $module) ? dirname($request->getIndex()) : $request->getIndex(); |
|
| 116 | 116 | return rtrim(str_replace('\\', '/', $name), '/').$assetRoot; |
| 117 | 117 | } |
| 118 | 118 | return rtrim(str_replace('\\', '/', $request->getIndex()), '/').$assetRoot; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | public static function getStaticRequestAsset(Application $application, Request $request, ?string $module = null):string |
| 146 | 146 | { |
| 147 | 147 | $assetRoot = static::getAssetRoot($application, $module); |
| 148 | - $name = static::writableAssets($application, $module) ? dirname($request->getIndex()):$request->getIndex(); |
|
| 148 | + $name = static::writableAssets($application, $module) ? dirname($request->getIndex()) : $request->getIndex(); |
|
| 149 | 149 | return rtrim(str_replace('\\', '/', $name), '/').$assetRoot; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -28,14 +28,14 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @var Tag[] |
| 30 | 30 | */ |
| 31 | - protected $tags=[]; |
|
| 31 | + protected $tags = []; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * 命令对象 |
| 35 | 35 | * |
| 36 | 36 | * @var CommandInterface[] |
| 37 | 37 | */ |
| 38 | - protected $commands=[]; |
|
| 38 | + protected $commands = []; |
|
| 39 | 39 | |
| 40 | 40 | public function __construct() |
| 41 | 41 | { |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function registerTag(Tag $tag) |
| 66 | 66 | { |
| 67 | - $this->tags[$tag->getName()] =$tag; |
|
| 67 | + $this->tags[$tag->getName()] = $tag; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -77,15 +77,15 @@ discard block |
||
| 77 | 77 | public function compileText(string $text, array $tagConfig = []):string |
| 78 | 78 | { |
| 79 | 79 | $this->applyTagConfig($tagConfig); |
| 80 | - $result = ''; |
|
| 80 | + $result = ''; |
|
| 81 | 81 | foreach (token_get_all($text) as $token) { |
| 82 | 82 | if (is_array($token)) { |
| 83 | 83 | list($tag, $content) = $token; |
| 84 | 84 | // 所有将要编译的文本 |
| 85 | 85 | // 跳过各种的PHP |
| 86 | 86 | if ($tag == T_INLINE_HTML) { |
| 87 | - $content=$this->proccesTags($content); |
|
| 88 | - $content=$this->proccesCommands($content); |
|
| 87 | + $content = $this->proccesTags($content); |
|
| 88 | + $content = $this->proccesCommands($content); |
|
| 89 | 89 | } |
| 90 | 90 | $result .= $content; |
| 91 | 91 | } else { |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | { |
| 110 | 110 | foreach ($this->tags as $tag) { |
| 111 | 111 | $pregExp = sprintf('/(!)?%s\s*(.+?)\s*%s/', preg_quote($tag->getOpen()), preg_quote($tag->getClose())); |
| 112 | - $text = preg_replace_callback($pregExp, function ($match) use ($tag) { |
|
| 112 | + $text = preg_replace_callback($pregExp, function($match) use ($tag) { |
|
| 113 | 113 | if ($match[1] === '!') { |
| 114 | 114 | return substr($match[0], 1); |
| 115 | 115 | } else { |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | protected function proccesCommands(string $text):string |
| 124 | 124 | { |
| 125 | - $pregExp ='/\B\@(\!)?([\w\x{4e00}-\x{9aff}]+)(\s*)(\( ( (?>[^()]+) | (?4) )* \) )? /ux'; |
|
| 126 | - $code = preg_replace_callback($pregExp, [$this,'doMatchCommand'], $text); |
|
| 125 | + $pregExp = '/\B\@(\!)?([\w\x{4e00}-\x{9aff}]+)(\s*)(\( ( (?>[^()]+) | (?4) )* \) )? /ux'; |
|
| 126 | + $code = preg_replace_callback($pregExp, [$this, 'doMatchCommand'], $text); |
|
| 127 | 127 | $error = preg_last_error(); |
| 128 | 128 | if ($error !== PREG_NO_ERROR) { |
| 129 | 129 | throw new Exception($error); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | list($input, $ignore, $name, $space) = $match; |
| 140 | 140 | $params = ''; |
| 141 | 141 | } |
| 142 | - if ($ignore ==='!') { |
|
| 142 | + if ($ignore === '!') { |
|
| 143 | 143 | return str_replace('@!', '@', $input); |
| 144 | 144 | } else { |
| 145 | 145 | foreach ($this->commands as $command) { |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | public function parseEchoValue($var):string |
| 9 | 9 | { |
| 10 | 10 | // 任意变量名: 中文点下划线英文数字 |
| 11 | - $code = preg_replace_callback('/\B[$](\?)?[:]([.\w\x{4e00}-\x{9aff}]+)(\s*)(\( ( (?>[^()]+) | (?4) )* \) )?/ux', [$this,'echoValueCallback'], $var); |
|
| 11 | + $code = preg_replace_callback('/\B[$](\?)?[:]([.\w\x{4e00}-\x{9aff}]+)(\s*)(\( ( (?>[^()]+) | (?4) )* \) )?/ux', [$this, 'echoValueCallback'], $var); |
|
| 12 | 12 | $error = preg_last_error(); |
| 13 | 13 | if ($error !== PREG_NO_ERROR) { |
| 14 | 14 | throw new Exception($error); |
@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | protected function echoValueCallback($matchs) |
| 20 | 20 | { |
| 21 | - $name=$matchs[2]; |
|
| 22 | - if ($matchs[1]==='?') { |
|
| 21 | + $name = $matchs[2]; |
|
| 22 | + if ($matchs[1] === '?') { |
|
| 23 | 23 | return '$this->has("'.$name.'")'; |
| 24 | 24 | } |
| 25 | 25 | if (isset($matchs[4])) { |
| 26 | 26 | if (preg_match('/\((.+)\)/', $matchs[4], $v)) { |
| 27 | 27 | $args = trim($v[1]); |
| 28 | - $args= strlen($args) ?','.$args:''; |
|
| 28 | + $args = strlen($args) ? ','.$args : ''; |
|
| 29 | 29 | return '$this->get("'.$name.'"'.$args.')'; |
| 30 | 30 | } |
| 31 | 31 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | protected function getStaticOutpath() |
| 111 | 111 | { |
| 112 | - $path = $this->config['assets-public'] ?? constant('SUDA_PUBLIC').'/assets/'. $this->getStaticName(); |
|
| 112 | + $path = $this->config['assets-public'] ?? constant('SUDA_PUBLIC').'/assets/'.$this->getStaticName(); |
|
| 113 | 113 | FileSystem::make($path); |
| 114 | 114 | return $path; |
| 115 | 115 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | { |
| 124 | 124 | $output = $this->config['output'] ?? constant('SUDA_DATA').'/template'; |
| 125 | 125 | FileSystem::make($output); |
| 126 | - return $output .'/'. $this->name.'-'.substr(md5_file($this->getSourcePath()), 10, 8).'.php'; |
|
| 126 | + return $output.'/'.$this->name.'-'.substr(md5_file($this->getSourcePath()), 10, 8).'.php'; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @return string|null |
| 133 | 133 | */ |
| 134 | - public function getSourcePath():?string |
|
| 134 | + public function getSourcePath(): ?string |
|
| 135 | 135 | { |
| 136 | 136 | return $this->source ?? null; |
| 137 | 137 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @return void |
| 154 | 154 | */ |
| 155 | - protected function compile(){ |
|
| 155 | + protected function compile() { |
|
| 156 | 156 | $sourcePath = $this->getSourcePath(); |
| 157 | 157 | $destPath = $this->getPath(); |
| 158 | 158 | if ($sourcePath === null) { |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | public function include(string $path) |
| 206 | 206 | { |
| 207 | 207 | $subfix = $this->config['subfix'] ?? ''; |
| 208 | - $included = new self(Resource::getPathByRelativePath($path. $subfix, dirname($this->source)), $this->config); |
|
| 208 | + $included = new self(Resource::getPathByRelativePath($path.$subfix, dirname($this->source)), $this->config); |
|
| 209 | 209 | $included->parent = $this; |
| 210 | 210 | echo $included->getRenderedString(); |
| 211 | 211 | } |
@@ -222,13 +222,13 @@ discard block |
||
| 222 | 222 | { |
| 223 | 223 | $this->prepareStaticSource(); |
| 224 | 224 | if (array_key_exists('assets-prefix', $this->config)) { |
| 225 | - $prefix = $this->config['assets-prefix'] ; |
|
| 225 | + $prefix = $this->config['assets-prefix']; |
|
| 226 | 226 | } elseif (defined('SUDA_ASSETS')) { |
| 227 | 227 | $prefix = constant('SUDA_ASSETS'); |
| 228 | 228 | } else { |
| 229 | 229 | $prefix = '/assets'; |
| 230 | 230 | } |
| 231 | - return $prefix .'/'.$this->getStaticName(); |
|
| 231 | + return $prefix.'/'.$this->getStaticName(); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | protected function prepareStaticSource() |