@@ -20,7 +20,7 @@ |
||
| 20 | 20 | } |
| 21 | 21 | public function getConfig(string $name) { |
| 22 | 22 | $defaultConfig = $this->getDefaultConfig(); |
| 23 | - return $this->config[$name] ?? $defaultConfig[$name];; |
|
| 23 | + return $this->config[$name] ?? $defaultConfig[$name]; ; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | abstract public function getDefaultConfig():array; |
@@ -15,14 +15,14 @@ |
||
| 15 | 15 | * @param int $expire 过期时间 |
| 16 | 16 | * @return bool |
| 17 | 17 | */ |
| 18 | - public function set(string $name, $value, int $expire=null):bool; |
|
| 18 | + public function set(string $name, $value, int $expire = null):bool; |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * 获取值 |
| 22 | 22 | * @param string $name 名 |
| 23 | 23 | * @return mixed|null |
| 24 | 24 | */ |
| 25 | - public function get(string $name, $defalut=null); |
|
| 25 | + public function get(string $name, $defalut = null); |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * 删除值 |
@@ -40,11 +40,11 @@ |
||
| 40 | 40 | $exstr = ''; |
| 41 | 41 | foreach ($array as $key => $value) { |
| 42 | 42 | $line = ''; |
| 43 | - $current=$arrname."['".addslashes($key)."']"; |
|
| 43 | + $current = $arrname."['".addslashes($key)."']"; |
|
| 44 | 44 | if (is_array($value)) { |
| 45 | 45 | $line .= self::parserArraySub($current, $value); |
| 46 | 46 | } else { |
| 47 | - $line = $current; |
|
| 47 | + $line = $current; |
|
| 48 | 48 | if (is_string($value)) { |
| 49 | 49 | $line .= "='".addslashes($value).'\';'.PHP_EOL; |
| 50 | 50 | } elseif (is_bool($value)) { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param mixed $def |
| 88 | 88 | * @return array 设置后的数组 |
| 89 | 89 | */ |
| 90 | - public static function set(array &$array, string $name, $value, $def=null):array |
|
| 90 | + public static function set(array &$array, string $name, $value, $def = null):array |
|
| 91 | 91 | { |
| 92 | 92 | $path = explode('.', $name); |
| 93 | 93 | $root = &$array; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $array[$key] = []; |
| 99 | 99 | } |
| 100 | 100 | } else { |
| 101 | - $array=[]; |
|
| 101 | + $array = []; |
|
| 102 | 102 | } |
| 103 | 103 | $array = &$array[$key]; |
| 104 | 104 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | $array[$key] = []; |
| 122 | 122 | } |
| 123 | 123 | } else { |
| 124 | - $array=[]; |
|
| 124 | + $array = []; |
|
| 125 | 125 | } |
| 126 | 126 | $array = &$array[$key]; |
| 127 | 127 | } |
@@ -40,11 +40,11 @@ |
||
| 40 | 40 | while (!feof($fp)) { |
| 41 | 41 | fseek($fp, $offset); |
| 42 | 42 | $content = fread($fp, $this->bufferSize); |
| 43 | - $content.=(feof($fp))? "\n":''; |
|
| 43 | + $content .= (feof($fp)) ? "\n" : ''; |
|
| 44 | 44 | $size = strpos($content, "\n"); |
| 45 | 45 | $offset += $size; |
| 46 | 46 | if ($content[$size - 1] === "\r") { |
| 47 | - $content = substr($content, 0, $size -1); |
|
| 47 | + $content = substr($content, 0, $size - 1); |
|
| 48 | 48 | } else { |
| 49 | 49 | $content = substr($content, 0, $size); |
| 50 | 50 | } |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | interface Template |
| 8 | 8 | { |
| 9 | - public function get(string $name=null, $default=null); |
|
| 9 | + public function get(string $name = null, $default = null); |
|
| 10 | 10 | public function set(string $name, $value); |
| 11 | 11 | public function has(string $name); |
| 12 | 12 | public function assign(array $values); |
@@ -40,14 +40,14 @@ |
||
| 40 | 40 | public function parseStartInsert($exp) |
| 41 | 41 | { |
| 42 | 42 | preg_match('/\((.+)\)/', $exp, $v); |
| 43 | - $name=trim(str_replace('\'', '-', trim($v[1], '"\''))); |
|
| 43 | + $name = trim(str_replace('\'', '-', trim($v[1], '"\''))); |
|
| 44 | 44 | return '<?php $this->insert(\''.$name.'\',function () { ?>'; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function parseInsert($exp) |
| 48 | 48 | { |
| 49 | 49 | preg_match('/\((.+)\)/', $exp, $v); |
| 50 | - $name=str_replace('\'', '-', trim($v[1], '"\'')); |
|
| 50 | + $name = str_replace('\'', '-', trim($v[1], '"\'')); |
|
| 51 | 51 | return "<?php \$this->exec('{$name}'); ?>"; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -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 |
@@ -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) { |