@@ -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; |
@@ -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 | } |
@@ -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) { |
@@ -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 |
@@ -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 | } |
@@ -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 | * 删除值 |
@@ -10,9 +10,9 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class Config |
12 | 12 | { |
13 | - public $config=[]; |
|
13 | + public $config = []; |
|
14 | 14 | |
15 | - public function load(string $path, array $extra =[]) |
|
15 | + public function load(string $path, array $extra = []) |
|
16 | 16 | { |
17 | 17 | $data = $this->loadConfig($path, $extra); |
18 | 18 | if ($data) { |
@@ -20,11 +20,11 @@ discard block |
||
20 | 20 | } |
21 | 21 | } |
22 | 22 | |
23 | - public function loadConfig(string $path, array $extra =[]):?array |
|
23 | + public function loadConfig(string $path, array $extra = []): ?array |
|
24 | 24 | { |
25 | - $data=null; |
|
25 | + $data = null; |
|
26 | 26 | if (!file_exists($path)) { |
27 | - $path =$this->resolve($path); |
|
27 | + $path = $this->resolve($path); |
|
28 | 28 | } |
29 | 29 | if ($path) { |
30 | 30 | $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION)); |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | throw new YamlException("parse yaml config error : missing yaml extension or spyc", 1); |
40 | 40 | } |
41 | 41 | $content = file_get_contents($path); |
42 | - $content =$this->parseValue($content, $extra); |
|
42 | + $content = $this->parseValue($content, $extra); |
|
43 | 43 | $data = \call_user_func_array($name, [$content]); |
44 | 44 | break; |
45 | 45 | case 'php': |
@@ -47,15 +47,15 @@ discard block |
||
47 | 47 | break; |
48 | 48 | case 'ini': |
49 | 49 | $content = file_get_contents($path); |
50 | - $content =$this->parseValue($content, $extra); |
|
51 | - $data = \parse_ini_string($content, true); |
|
50 | + $content = $this->parseValue($content, $extra); |
|
51 | + $data = \parse_ini_string($content, true); |
|
52 | 52 | break; |
53 | 53 | case 'json': |
54 | 54 | default: |
55 | 55 | $content = file_get_contents($path); |
56 | - $content =$this->parseValue($content, $extra); |
|
56 | + $content = $this->parseValue($content, $extra); |
|
57 | 57 | $data = json_decode($content, true); |
58 | - if (json_last_error()!==JSON_ERROR_NONE) { |
|
58 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
59 | 59 | throw new JSONException(json_last_error()); |
60 | 60 | } |
61 | 61 | } |
@@ -63,22 +63,22 @@ discard block |
||
63 | 63 | return $data; |
64 | 64 | } |
65 | 65 | |
66 | - protected function parseValue(string $content, array $extra =[]):string |
|
66 | + protected function parseValue(string $content, array $extra = []):string |
|
67 | 67 | { |
68 | - return preg_replace_callback('/\$\{(.+?)\}/', function ($matchs) use ($extra) { |
|
68 | + return preg_replace_callback('/\$\{(.+?)\}/', function($matchs) use ($extra) { |
|
69 | 69 | $name = $matchs[1]; |
70 | 70 | $value = $matchs[0]; |
71 | - if (($value = ArrayDotAccess::get($extra, $name, null))!==null) { |
|
71 | + if (($value = ArrayDotAccess::get($extra, $name, null)) !== null) { |
|
72 | 72 | } elseif (defined($name)) { |
73 | 73 | $value = constant($name); |
74 | 74 | } else { |
75 | 75 | $value = $this->get($name, $value); |
76 | 76 | } |
77 | - return is_string($value)?trim(json_encode($value), '"'):$value; |
|
77 | + return is_string($value) ?trim(json_encode($value), '"') : $value; |
|
78 | 78 | }, $content); |
79 | 79 | } |
80 | 80 | |
81 | - public static function resolve(string $path):?string |
|
81 | + public static function resolve(string $path): ?string |
|
82 | 82 | { |
83 | 83 | if (file_exists($path)) { |
84 | 84 | return $path; |
@@ -89,16 +89,16 @@ discard block |
||
89 | 89 | } else { |
90 | 90 | $basepath = pathinfo($path, PATHINFO_FILENAME); |
91 | 91 | } |
92 | - if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) { |
|
92 | + if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) { |
|
93 | 93 | if (function_exists('yaml_parse') || class_exists('Spyc')) { |
94 | 94 | return $conf; |
95 | 95 | } |
96 | 96 | } |
97 | - if (file_exists($conf=$basepath.'.json')) { |
|
97 | + if (file_exists($conf = $basepath.'.json')) { |
|
98 | 98 | return $conf; |
99 | - } elseif (file_exists($conf=$basepath.'.php')) { |
|
99 | + } elseif (file_exists($conf = $basepath.'.php')) { |
|
100 | 100 | return $conf; |
101 | - } elseif (file_exists($conf=$basepath.'.ini')) { |
|
101 | + } elseif (file_exists($conf = $basepath.'.ini')) { |
|
102 | 102 | return $conf; |
103 | 103 | } |
104 | 104 | } |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | |
113 | 113 | public function assign(array $config) |
114 | 114 | { |
115 | - return $this->config=array_merge($this->config, $config); |
|
115 | + return $this->config = array_merge($this->config, $config); |
|
116 | 116 | } |
117 | 117 | |
118 | - public function get(string $name=null, $default=null) |
|
118 | + public function get(string $name = null, $default = null) |
|
119 | 119 | { |
120 | 120 | if (is_null($name)) { |
121 | 121 | return $this->config; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | return ArrayDotAccess::get($this->config, $name, $default); |
124 | 124 | } |
125 | 125 | |
126 | - public function set(string $name, $value, $combine=null) |
|
126 | + public function set(string $name, $value, $combine = null) |
|
127 | 127 | { |
128 | 128 | return ArrayDotAccess::set($this->config, $name, $value, $combine); |
129 | 129 | } |