@@ -6,7 +6,7 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | interface TemplateInterface |
| 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); |
@@ -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 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param string $className |
| 57 | 57 | * @return string|null |
| 58 | 58 | */ |
| 59 | - public function getClassPath(string $className):?string |
|
| 59 | + public function getClassPath(string $className): ?string |
|
| 60 | 60 | { |
| 61 | 61 | // 搜索路径 |
| 62 | 62 | foreach ($this->includePath as $includeNamespace => $includePaths) { |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | * @param string $className |
| 79 | 79 | * @return string|null |
| 80 | 80 | */ |
| 81 | - protected function getClassPathByAlias(string $includePath, string $className):?string |
|
| 81 | + protected function getClassPathByAlias(string $includePath, string $className): ?string |
|
| 82 | 82 | { |
| 83 | - $namepath=static::formatSeparator($className); |
|
| 84 | - $className=static::realName($className); |
|
| 83 | + $namepath = static::formatSeparator($className); |
|
| 84 | + $className = static::realName($className); |
|
| 85 | 85 | foreach ($this->namespace as $namespace) { |
| 86 | 86 | $path = $includePath.DIRECTORY_SEPARATOR.$namespace.DIRECTORY_SEPARATOR.$namepath.'.php'; |
| 87 | 87 | if ($path = static::realPath($path)) { |
@@ -103,16 +103,16 @@ discard block |
||
| 103 | 103 | * @param string $className |
| 104 | 104 | * @return string|null |
| 105 | 105 | */ |
| 106 | - protected function getClassPathByName(string $includeNamespace, string $includePath, string $className):?string |
|
| 106 | + protected function getClassPathByName(string $includeNamespace, string $includePath, string $className): ?string |
|
| 107 | 107 | { |
| 108 | 108 | if (is_numeric($includeNamespace)) { |
| 109 | 109 | $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
| 110 | 110 | } else { |
| 111 | 111 | $nl = strlen($includeNamespace); |
| 112 | 112 | if (substr(static::realName($className), 0, $nl) === $includeNamespace) { |
| 113 | - $path=$includePath.DIRECTORY_SEPARATOR.static::formatSeparator(substr($className, $nl)).'.php'; |
|
| 113 | + $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator(substr($className, $nl)).'.php'; |
|
| 114 | 114 | } else { |
| 115 | - $path=$includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
|
| 115 | + $path = $includePath.DIRECTORY_SEPARATOR.static::formatSeparator($className).'.php'; |
|
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | if ($path = static::realPath($path)) { |
@@ -5,11 +5,11 @@ |
||
| 5 | 5 | |
| 6 | 6 | trait LoaderAwareTrait |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * 加载器 |
|
| 10 | - * |
|
| 11 | - * @var Loader |
|
| 12 | - */ |
|
| 8 | + /** |
|
| 9 | + * 加载器 |
|
| 10 | + * |
|
| 11 | + * @var Loader |
|
| 12 | + */ |
|
| 13 | 13 | protected $loader; |
| 14 | 14 | |
| 15 | 15 | |
@@ -15,14 +15,14 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @var array |
| 17 | 17 | */ |
| 18 | - protected $namespace=[ __NAMESPACE__ ]; |
|
| 18 | + protected $namespace = [__NAMESPACE__]; |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * 包含路径 |
| 22 | 22 | * |
| 23 | 23 | * @var array |
| 24 | 24 | */ |
| 25 | - protected $includePath=[]; |
|
| 25 | + protected $includePath = []; |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * 将JAVA,路径分割转换为PHP分割符 |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public static function realName(string $name):string |
| 34 | 34 | { |
| 35 | - return str_replace(['.','/'], '\\', $name); |
|
| 35 | + return str_replace(['.', '/'], '\\', $name); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param string $name |
| 42 | 42 | * @return string|null |
| 43 | 43 | */ |
| 44 | - public static function realPath(string $name):?string |
|
| 44 | + public static function realPath(string $name): ?string |
|
| 45 | 45 | { |
| 46 | 46 | return Path::format($name); |
| 47 | 47 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param string $filename |
| 53 | 53 | * @return string|null |
| 54 | 54 | */ |
| 55 | - public function import(string $filename):?string |
|
| 55 | + public function import(string $filename): ?string |
|
| 56 | 56 | { |
| 57 | 57 | if ($filename = static::realPath($filename)) { |
| 58 | 58 | @require_once $filename; |
@@ -68,16 +68,16 @@ discard block |
||
| 68 | 68 | return null; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function addIncludePath(string $path, string $namespace=null) |
|
| 71 | + public function addIncludePath(string $path, string $namespace = null) |
|
| 72 | 72 | { |
| 73 | 73 | if ($path = static::realPath($path)) { |
| 74 | 74 | $namespace = $namespace ?? 0; |
| 75 | 75 | if (array_key_exists($namespace, $this->includePath)) { |
| 76 | 76 | if (!\in_array($path, $this->includePath[$namespace])) { |
| 77 | - $this->includePath[$namespace][]=$path; |
|
| 77 | + $this->includePath[$namespace][] = $path; |
|
| 78 | 78 | } |
| 79 | 79 | } else { |
| 80 | - $this->includePath[$namespace][]=$path; |
|
| 80 | + $this->includePath[$namespace][] = $path; |
|
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | public function setNamespace(string $namespace) |
| 96 | 96 | { |
| 97 | 97 | if (!in_array($namespace, $this->namespace)) { |
| 98 | - $this->namespace[]=$namespace; |
|
| 98 | + $this->namespace[] = $namespace; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | { |
| 10 | 10 | public static function formatSeparator(string $path):string |
| 11 | 11 | { |
| 12 | - return str_replace(['\\','/'], DIRECTORY_SEPARATOR, $path); |
|
| 12 | + return str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | public static function toAbsolutePath(string $path, string $separator = DIRECTORY_SEPARATOR):string{ |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $subpath = substr($subpath, 1); |
| 31 | 31 | } else { |
| 32 | 32 | if (strpos($subpath, ':/') === false) { |
| 33 | - $subpath=str_replace(['/', '\\'], '/', getcwd()).'/'.$subpath; |
|
| 33 | + $subpath = str_replace(['/', '\\'], '/', getcwd()).'/'.$subpath; |
|
| 34 | 34 | } |
| 35 | 35 | list($root, $subpath) = explode(':/', $subpath, 2); |
| 36 | 36 | $root .= ':'.DIRECTORY_SEPARATOR; |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | } elseif ($name === '.') { |
| 49 | 49 | continue; |
| 50 | 50 | } elseif (strlen($name)) { |
| 51 | - $absulotePaths[]=$name; |
|
| 51 | + $absulotePaths[] = $name; |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | return implode($separator, $absulotePaths); |
@@ -57,20 +57,20 @@ discard block |
||
| 57 | 57 | protected static function parsePathSchemeSubpath(string $path):array |
| 58 | 58 | { |
| 59 | 59 | if (static::getHomePath() !== null && strpos($path, '~') === 0) { |
| 60 | - $scheme =''; |
|
| 61 | - $subpath = static::getHomePath() .DIRECTORY_SEPARATOR.substr($path, 1); |
|
| 60 | + $scheme = ''; |
|
| 61 | + $subpath = static::getHomePath().DIRECTORY_SEPARATOR.substr($path, 1); |
|
| 62 | 62 | } elseif (strpos($path, '://') !== false) { |
| 63 | 63 | list($scheme, $subpath) = explode('://', $path, 2); |
| 64 | - $scheme.='://'; |
|
| 64 | + $scheme .= '://'; |
|
| 65 | 65 | } else { |
| 66 | - $scheme =''; |
|
| 66 | + $scheme = ''; |
|
| 67 | 67 | $subpath = $path; |
| 68 | 68 | } |
| 69 | 69 | return [$scheme, $subpath]; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
| 73 | - public static function getHomePath():?string { |
|
| 73 | + public static function getHomePath(): ?string { |
|
| 74 | 74 | if (defined('USER_HOME_PATH')) { |
| 75 | 75 | return constant('USER_HOME_PATH'); |
| 76 | 76 | } |
@@ -14,12 +14,12 @@ discard block |
||
| 14 | 14 | * @param string $path 目标路径 |
| 15 | 15 | * @return string|null 返回格式化结果,如果路径不存在则返回NULL |
| 16 | 16 | */ |
| 17 | - public static function format(string $path):?string |
|
| 17 | + public static function format(string $path): ?string |
|
| 18 | 18 | { |
| 19 | - return static::existCharset($path, ['GBK','GB2312','BIG5']); |
|
| 19 | + return static::existCharset($path, ['GBK', 'GB2312', 'BIG5']); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public static function existCharset(string $path, array $charset):?string |
|
| 22 | + public static function existCharset(string $path, array $charset): ?string |
|
| 23 | 23 | { |
| 24 | 24 | $abspath = static::toAbsolutePath($path); |
| 25 | 25 | if (static::existCase($abspath)) { |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @return boolean |
| 71 | 71 | */ |
| 72 | 72 | public static function isRelativePath(string $path):bool { |
| 73 | - $path = \str_replace('\\','/', $path); |
|
| 73 | + $path = \str_replace('\\', '/', $path); |
|
| 74 | 74 | return !(strpos($path, ':/') > 0 || strpos($path, '/') === 0); |
| 75 | 75 | } |
| 76 | 76 | } |