@@ -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) { |
@@ -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 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | |
51 | 51 | public static function credibleLoad(string $name): Template |
52 | 52 | { |
53 | - if (($template = static::load($name))!==null) { |
|
53 | + if (($template = static::load($name)) !== null) { |
|
54 | 54 | return $template; |
55 | 55 | } |
56 | 56 | $empty = new EmptyTemplate; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | protected $extends; |
18 | 18 | |
19 | - public function get(string $name=null, $default=null) |
|
19 | + public function get(string $name = null, $default = null) |
|
20 | 20 | { |
21 | 21 | if (is_null($name)) { |
22 | 22 | return $this->value; |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | public function assign(array $values) |
39 | 39 | { |
40 | - $this->value=array_merge($this->value, $values); |
|
40 | + $this->value = array_merge($this->value, $values); |
|
41 | 41 | return $this; |
42 | 42 | } |
43 | 43 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | public function getRenderedString() |
64 | 64 | { |
65 | - $text = 'EmptyTemplate<'.$this->get('name', 'null').'>'; |
|
65 | + $text = 'EmptyTemplate<'.$this->get('name', 'null').'>'; |
|
66 | 66 | if ($this->extends) { |
67 | 67 | $text = $this->extends->getRenderedString(); |
68 | 68 | } |
@@ -48,12 +48,12 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @return array|null |
50 | 50 | */ |
51 | - public function json():?array { |
|
51 | + public function json(): ?array { |
|
52 | 52 | if (isset($this->json)) { |
53 | 53 | return $this->json; |
54 | 54 | } |
55 | - $data =json_decode($this->input(), true, 512, JSON_BIGINT_AS_STRING); |
|
56 | - if (json_last_error()!==JSON_ERROR_NONE) { |
|
55 | + $data = json_decode($this->input(), true, 512, JSON_BIGINT_AS_STRING); |
|
56 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
57 | 57 | $this->json = null; |
58 | 58 | } |
59 | 59 | return $this->json = $data; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param mixed $default |
67 | 67 | * @return mixed |
68 | 68 | */ |
69 | - public function get(?string $name=null, $default =null) |
|
69 | + public function get(?string $name = null, $default = null) |
|
70 | 70 | { |
71 | 71 | return $this->getParameter($name, $default); |
72 | 72 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param mixed $default |
79 | 79 | * @return mixed 获取的值 |
80 | 80 | */ |
81 | - public static function post(?string $name=null, $default=null) |
|
81 | + public static function post(?string $name = null, $default = null) |
|
82 | 82 | { |
83 | 83 | if (is_null($name)) { |
84 | 84 | return $_POST; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @param string|null $name |
129 | 129 | * @return boolean |
130 | 130 | */ |
131 | - public function hasGet(?string $name=null) |
|
131 | + public function hasGet(?string $name = null) |
|
132 | 132 | { |
133 | 133 | $get = $this->getParameter(); |
134 | 134 | if (is_null($name)) { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return boolean |
159 | 159 | */ |
160 | - public function hasPost(?string $name=null) |
|
160 | + public function hasPost(?string $name = null) |
|
161 | 161 | { |
162 | 162 | $post = $this->post(); |
163 | 163 | if ($name) { |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * @param mixed $default |
181 | 181 | * @return mixed |
182 | 182 | */ |
183 | - abstract public function getHeader(string $name, $default =null); |
|
183 | + abstract public function getHeader(string $name, $default = null); |
|
184 | 184 | /** |
185 | 185 | * 获取请求参数 |
186 | 186 | * |
@@ -53,9 +53,9 @@ |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | - * Get 服务器属性 |
|
57 | - * |
|
58 | - * @return array |
|
59 | - */ |
|
56 | + * Get 服务器属性 |
|
57 | + * |
|
58 | + * @return array |
|
59 | + */ |
|
60 | 60 | abstract public function getServer(); |
61 | 61 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return array|null |
46 | 46 | */ |
47 | - public function json():?array; |
|
47 | + public function json(): ?array; |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * 获取GET参数 |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param mixed $default |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public function get(?string $name=null, $default =null); |
|
56 | + public function get(?string $name = null, $default = null); |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * 获取POST请求的值 |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param mixed $default |
63 | 63 | * @return mixed 获取的值 |
64 | 64 | */ |
65 | - public static function post(?string $name=null, $default=null); |
|
65 | + public static function post(?string $name = null, $default = null); |
|
66 | 66 | |
67 | 67 | /** |
68 | 68 | * 获取HTTP输入 |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param string|null $name |
86 | 86 | * @return boolean |
87 | 87 | */ |
88 | - public function hasGet(?string $name=null); |
|
88 | + public function hasGet(?string $name = null); |
|
89 | 89 | |
90 | 90 | /** |
91 | 91 | * 判断是否有JSON数据请求 |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return boolean |
101 | 101 | */ |
102 | - public function hasPost(?string $name=null); |
|
102 | + public function hasPost(?string $name = null); |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * 获取参数 |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @param mixed $default |
116 | 116 | * @return mixed |
117 | 117 | */ |
118 | - public function getHeader(string $name, $default =null); |
|
118 | + public function getHeader(string $name, $default = null); |
|
119 | 119 | |
120 | 120 | // Uri |
121 | 121 | /** |