@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param mixed $default |
| 35 | 35 | * @return mixed |
| 36 | 36 | */ |
| 37 | - public function get(string $name=null, $default=null); |
|
| 37 | + public function get(string $name = null, $default = null); |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * 删除一个或者全部Session数据 |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param string|null $name |
| 43 | 43 | * @return bool |
| 44 | 44 | */ |
| 45 | - public function delete(?string $name=null):bool; |
|
| 45 | + public function delete(?string $name = null):bool; |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * 检测是否存在Session |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param mixed $default |
| 26 | 26 | * @return mixed |
| 27 | 27 | */ |
| 28 | - public function get(string $name, $default=null); |
|
| 28 | + public function get(string $name, $default = null); |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * 删除一个或者全部Cache数据 |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param string|null $name |
| 34 | 34 | * @return bool |
| 35 | 35 | */ |
| 36 | - public function delete(?string $name=null):bool; |
|
| 36 | + public function delete(?string $name = null):bool; |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * 检测是否存在Cache |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | if (is_string($id = $request->getCookie($name))) { |
| 67 | 67 | session_id($id); |
| 68 | - }else{ |
|
| 68 | + } else { |
|
| 69 | 69 | $id = md5($path.$request->getRemoteAddr().uniqid()); |
| 70 | 70 | session_id($id); |
| 71 | 71 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | public function get(string $name = null, $default = null) |
| 101 | 101 | { |
| 102 | 102 | if ($name !== null) { |
| 103 | - return $this->has($name) ?$_SESSION[$name]:$default; |
|
| 103 | + return $this->has($name) ? $_SESSION[$name] : $default; |
|
| 104 | 104 | } else { |
| 105 | 105 | return $_SESSION; |
| 106 | 106 | } |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | { |
| 23 | 23 | $content = $this->content; |
| 24 | 24 | $response->setType($content->getExtension()); |
| 25 | - $response->setHeader('Content-Disposition', 'attachment;filename="' . $content->getBasename().'"'); |
|
| 25 | + $response->setHeader('Content-Disposition', 'attachment;filename="'.$content->getBasename().'"'); |
|
| 26 | 26 | $response->setHeader('Cache-Control', 'max-age=0'); |
| 27 | 27 | return new DataStream($content); |
| 28 | 28 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | public function parseEchoValue($var):string |
| 7 | 7 | { |
| 8 | 8 | // 任意变量名: 中文点下划线英文数字 |
| 9 | - $code = preg_replace_callback('/\B[$](\?)?[:]([.\w\x{4e00}-\x{9aff}]+)(\s*)(\( ( (?>[^()]+) | (?4) )* \) )?/ux', [$this,'echoValueCallback'], $var); |
|
| 9 | + $code = preg_replace_callback('/\B[$](\?)?[:]([.\w\x{4e00}-\x{9aff}]+)(\s*)(\( ( (?>[^()]+) | (?4) )* \) )?/ux', [$this, 'echoValueCallback'], $var); |
|
| 10 | 10 | $error = preg_last_error(); |
| 11 | 11 | if ($error !== PREG_NO_ERROR) { |
| 12 | 12 | throw new \Exception($error); |
@@ -16,14 +16,14 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | protected function echoValueCallback($matchs) |
| 18 | 18 | { |
| 19 | - $name=$matchs[2]; |
|
| 20 | - if ($matchs[1]==='?') { |
|
| 19 | + $name = $matchs[2]; |
|
| 20 | + if ($matchs[1] === '?') { |
|
| 21 | 21 | return '$this->has("'.$name.'")'; |
| 22 | 22 | } |
| 23 | 23 | if (isset($matchs[4])) { |
| 24 | 24 | if (preg_match('/\((.+)\)/', $matchs[4], $v)) { |
| 25 | 25 | $args = trim($v[1]); |
| 26 | - $args= strlen($args) ?','.$args:''; |
|
| 26 | + $args = strlen($args) ? ','.$args : ''; |
|
| 27 | 27 | return '$this->get("'.$name.'"'.$args.')'; |
| 28 | 28 | } |
| 29 | 29 | } |
@@ -26,14 +26,14 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @var Tag[] |
| 28 | 28 | */ |
| 29 | - protected $tags=[]; |
|
| 29 | + protected $tags = []; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * 命令对象 |
| 33 | 33 | * |
| 34 | 34 | * @var CommandInterface[] |
| 35 | 35 | */ |
| 36 | - protected $commands=[]; |
|
| 36 | + protected $commands = []; |
|
| 37 | 37 | |
| 38 | 38 | public function __construct() |
| 39 | 39 | { |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function registerTag(Tag $tag) |
| 64 | 64 | { |
| 65 | - $this->tags[$tag->getName()] =$tag; |
|
| 65 | + $this->tags[$tag->getName()] = $tag; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -75,15 +75,15 @@ discard block |
||
| 75 | 75 | public function compileText(string $text, array $tagConfig = []):string |
| 76 | 76 | { |
| 77 | 77 | $this->applyTagConfig($tagConfig); |
| 78 | - $result = ''; |
|
| 78 | + $result = ''; |
|
| 79 | 79 | foreach (token_get_all($text) as $token) { |
| 80 | 80 | if (is_array($token)) { |
| 81 | 81 | list($tag, $content) = $token; |
| 82 | 82 | // 所有将要编译的文本 |
| 83 | 83 | // 跳过各种的PHP |
| 84 | 84 | if ($tag == T_INLINE_HTML) { |
| 85 | - $content=$this->proccesTags($content); |
|
| 86 | - $content=$this->proccesCommands($content); |
|
| 85 | + $content = $this->proccesTags($content); |
|
| 86 | + $content = $this->proccesCommands($content); |
|
| 87 | 87 | } |
| 88 | 88 | $result .= $content; |
| 89 | 89 | } else { |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | { |
| 108 | 108 | foreach ($this->tags as $tag) { |
| 109 | 109 | $pregExp = sprintf('/(!)?%s\s*(.+?)\s*%s/', preg_quote($tag->getOpen()), preg_quote($tag->getClose())); |
| 110 | - $text = \preg_replace_callback($pregExp, function ($match) use ($tag) { |
|
| 110 | + $text = \preg_replace_callback($pregExp, function($match) use ($tag) { |
|
| 111 | 111 | if ($match[1] === '!') { |
| 112 | 112 | return substr($match[0], 1); |
| 113 | 113 | } else { |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | protected function proccesCommands(string $text):string |
| 122 | 122 | { |
| 123 | - $pregExp ='/\B\@(\!)?([\w\x{4e00}-\x{9aff}]+)(\s*)(\( ( (?>[^()]+) | (?4) )* \) )? /ux'; |
|
| 124 | - $code = preg_replace_callback($pregExp, [$this,'doMatchCommand'], $text); |
|
| 123 | + $pregExp = '/\B\@(\!)?([\w\x{4e00}-\x{9aff}]+)(\s*)(\( ( (?>[^()]+) | (?4) )* \) )? /ux'; |
|
| 124 | + $code = preg_replace_callback($pregExp, [$this, 'doMatchCommand'], $text); |
|
| 125 | 125 | $error = preg_last_error(); |
| 126 | 126 | if ($error !== PREG_NO_ERROR) { |
| 127 | 127 | throw new \Exception($error); |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | list($input, $ignore, $name, $space) = $match; |
| 138 | 138 | $params = ''; |
| 139 | 139 | } |
| 140 | - if ($ignore ==='!') { |
|
| 140 | + if ($ignore === '!') { |
|
| 141 | 141 | return \str_replace('@!', '@', $input); |
| 142 | 142 | } else { |
| 143 | 143 | foreach ($this->commands as $command) { |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | $this->content = $content; |
| 40 | 40 | $this->name = $name; |
| 41 | 41 | $this->open = $open; |
| 42 | - $this->close= $close; |
|
| 42 | + $this->close = $close; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | public function compile(string $content):string |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function __construct($file) |
| 31 | 31 | { |
| 32 | - $this->file = $file instanceof SplFileObject? $file : new SplFileObject($file); |
|
| 32 | + $this->file = $file instanceof SplFileObject ? $file : new SplFileObject($file); |
|
| 33 | 33 | $this->mime = MimeType::getMimeType($this->file->getExtension()); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | protected function sendFileByRange(Response $response, array $range) |
| 91 | 91 | { |
| 92 | - $response->write(new DataStream($this->file, $range['start'], $range['end'] - $range['start'] + 1)); |
|
| 92 | + $response->write(new DataStream($this->file, $range['start'], $range['end'] - $range['start'] + 1)); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | protected function sendMultipleRangePart(Response $response, array $range) |
| 120 | 120 | { |
| 121 | 121 | $response->write('Content-Type: '.$this->mime."\r\n"); |
| 122 | - $response->write('Content-Range: '.$this->getRangeHeader($range) ."\r\n\r\n"); |
|
| 122 | + $response->write('Content-Range: '.$this->getRangeHeader($range)."\r\n\r\n"); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * @param string $range |
| 179 | 179 | * @return array |
| 180 | 180 | */ |
| 181 | - protected function parseRange(string $range):?array |
|
| 181 | + protected function parseRange(string $range): ?array |
|
| 182 | 182 | { |
| 183 | 183 | $range = trim($range); |
| 184 | 184 | if (strrpos($range, '-') === strlen($range) - 1) { |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | ]; |
| 189 | 189 | } elseif (\strpos($range, '-') !== false) { |
| 190 | 190 | list($start, $end) = \explode('-', $range, 2); |
| 191 | - return ['start' => intval($start) , 'end' => intval($end) ]; |
|
| 191 | + return ['start' => intval($start), 'end' => intval($end)]; |
|
| 192 | 192 | } |
| 193 | 193 | return null; |
| 194 | 194 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | throw new FileLoggerException(__CLASS__.':'.sprintf('cannot create log file')); |
| 71 | 71 | } |
| 72 | 72 | $this->latest = $this->getConfig('save-path').'/'.$this->getConfig('file-name'); |
| 73 | - \register_shutdown_function([$this,'save']); |
|
| 73 | + \register_shutdown_function([$this, 'save']); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | public function getDefaultConfig():array |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | protected function packLogFile() |
| 90 | 90 | { |
| 91 | 91 | $logFile = $this->latest; |
| 92 | - $path = preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path') .'/'.date('Y-m-d').'.zip'); |
|
| 92 | + $path = preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path').'/'.date('Y-m-d').'.zip'); |
|
| 93 | 93 | $zip = $this->getZipArchive($path); |
| 94 | 94 | if ($zip !== null) { |
| 95 | - if ($zip->addFile($logFile, date('Y-m-d'). '-'. $zip->numFiles .'.log')) { |
|
| 95 | + if ($zip->addFile($logFile, date('Y-m-d').'-'.$zip->numFiles.'.log')) { |
|
| 96 | 96 | array_push($this->removeFiles, $logFile); |
| 97 | 97 | } |
| 98 | 98 | if (\is_dir($this->getConfig('save-pack-path'))) { |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $zip->close(); |
| 107 | 107 | } else { |
| 108 | 108 | if (is_file($logFile) && file_exists($logFile)) { |
| 109 | - rename($logFile, $this->getConfig('save-path') . '/' . date('Y-m-d'). '-'. substr(md5_file($logFile), 0, 8).'.log'); |
|
| 109 | + rename($logFile, $this->getConfig('save-path').'/'.date('Y-m-d').'-'.substr(md5_file($logFile), 0, 8).'.log'); |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | } elseif (null === $val) { |
| 205 | 205 | $val = 'null'; |
| 206 | 206 | } |
| 207 | - $replace['{' . $key . '}'] = $val; |
|
| 207 | + $replace['{'.$key.'}'] = $val; |
|
| 208 | 208 | } |
| 209 | 209 | return strtr($message, $replace); |
| 210 | 210 | } |