@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | $rpos = \strrpos($name, ':'); |
56 | 56 | if ($rpos > 0) { |
57 | 57 | $module = substr($name, 0, $rpos); |
58 | - $name = \substr($name, $rpos+1); |
|
59 | - $moduleFull = $this->getFullName($module); |
|
58 | + $name = \substr($name, $rpos + 1); |
|
59 | + $moduleFull = $this->getFullName($module); |
|
60 | 60 | return [$moduleFull, $name]; |
61 | 61 | } |
62 | 62 | if ($rpos === 0) { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | if (\array_key_exists($version, $this->knownsFullName[$name])) { |
78 | 78 | return $this->knownsFullName[$name][$version]; |
79 | 79 | } |
80 | - return $hasVersion?$name.':'.$version:end($this->knownsFullName[$name]); |
|
80 | + return $hasVersion ? $name.':'.$version : end($this->knownsFullName[$name]); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | protected function getLikeName(string $name):string |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | |
85 | 85 | public function getRoute(string $groupName): GroupRoutes |
86 | 86 | { |
87 | - $group = $groupName === 'default' ? '': '-'. $groupName; |
|
88 | - $routeConfig = $this->getConfigFrom('route'.$group, ['group' => $group,]); |
|
89 | - $routes = new GroupRoutes($groupName); |
|
87 | + $group = $groupName === 'default' ? '' : '-'.$groupName; |
|
88 | + $routeConfig = $this->getConfigFrom('route'.$group, ['group' => $group, ]); |
|
89 | + $routes = new GroupRoutes($groupName); |
|
90 | 90 | if (\is_array($routeConfig)) { |
91 | 91 | // debug()->debug('load route {group} from {module}',['group'=>$groupName, 'module' => $this->getFullName()]); |
92 | 92 | $prefix = $this->config->get('route.prefix', ''); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function getFullName() |
143 | 143 | { |
144 | - return $this->name .':'. $this->version; |
|
144 | + return $this->name.':'.$this->version; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -42,9 +42,9 @@ |
||
42 | 42 | $extension !== 'module') { |
43 | 43 | return null; |
44 | 44 | } |
45 | - $zip=new ZipArchive; |
|
45 | + $zip = new ZipArchive; |
|
46 | 46 | if ($zip->open($path, ZipArchive::CHECKCONS)) { |
47 | - $unzipPath = $unpackPath.'/'. pathinfo($path, PATHINFO_FILENAME) .'-'.substr(md5_file($path), 0, 8); |
|
47 | + $unzipPath = $unpackPath.'/'.pathinfo($path, PATHINFO_FILENAME).'-'.substr(md5_file($path), 0, 8); |
|
48 | 48 | $zip->extractTo($unzipPath); |
49 | 49 | $zip->close(); |
50 | 50 | return Config::resolve($unzipPath.'/module'); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | public function registerModule() |
141 | 141 | { |
142 | 142 | $scan = $this->getContext()->getConfig()->get('app.module.scan-path', []); |
143 | - $cache = $this->getContext()->getApplication()->getDataPath() .'/module-cache'; |
|
143 | + $cache = $this->getContext()->getApplication()->getDataPath().'/module-cache'; |
|
144 | 144 | FileSystem::makes($cache); |
145 | 145 | // 扫描加载 |
146 | 146 | foreach (Builder::scan($scan, $cache) as $module) { |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * @param string $name |
191 | 191 | * @return Module|null |
192 | 192 | */ |
193 | - public function find(string $name):?Module |
|
193 | + public function find(string $name): ?Module |
|
194 | 194 | { |
195 | 195 | $fullName = $this->finder->getFullName($name); |
196 | 196 | return $this->module[$fullName] ?? null; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function loadFromModule(Manager $manager) |
52 | 52 | { |
53 | - $groups = $this->applicaton->getConfig()->get('app.active', ['default']); |
|
53 | + $groups = $this->applicaton->getConfig()->get('app.active', ['default']); |
|
54 | 54 | foreach ($groups as $group) { |
55 | 55 | $manager->loadRoute($group, $this); |
56 | 56 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param Request $request |
79 | 79 | * @return MatchResult|null |
80 | 80 | */ |
81 | - public function match(Request $request):?MatchResult |
|
81 | + public function match(Request $request): ?MatchResult |
|
82 | 82 | { |
83 | 83 | foreach ($this->routes as $group => $routes) { |
84 | 84 | if (($result = $routes->match($request)) !== null) { |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | $this->config = $config; |
21 | 21 | } |
22 | 22 | |
23 | - public function load(string $path, array $extra =[]) |
|
23 | + public function load(string $path, array $extra = []) |
|
24 | 24 | { |
25 | 25 | $data = $this->loadConfig($path, $extra); |
26 | 26 | if ($data) { |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | |
36 | 36 | public function assign(array $config) |
37 | 37 | { |
38 | - return $this->config=array_merge($this->config, $config); |
|
38 | + return $this->config = array_merge($this->config, $config); |
|
39 | 39 | } |
40 | 40 | |
41 | - public function get(string $name=null, $default=null) |
|
41 | + public function get(string $name = null, $default = null) |
|
42 | 42 | { |
43 | 43 | if (is_null($name)) { |
44 | 44 | return $this->config; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | return ArrayDotAccess::get($this->config, $name, $default); |
47 | 47 | } |
48 | 48 | |
49 | - public function set(string $name, $value, $combine=null) |
|
49 | + public function set(string $name, $value, $combine = null) |
|
50 | 50 | { |
51 | 51 | return ArrayDotAccess::set($this->config, $name, $value, $combine); |
52 | 52 | } |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | return ArrayDotAccess::exist($this->config, $name); |
57 | 57 | } |
58 | 58 | |
59 | - public function parseValue(string $content, array $extra =[]):string |
|
59 | + public function parseValue(string $content, array $extra = []):string |
|
60 | 60 | { |
61 | - return preg_replace_callback('/\$\{(.+?)\}/', function ($matchs) use ($extra) { |
|
61 | + return preg_replace_callback('/\$\{(.+?)\}/', function($matchs) use ($extra) { |
|
62 | 62 | $name = $matchs[1]; |
63 | - if (($value = ArrayDotAccess::get($extra, $name, null))!==null) { |
|
63 | + if (($value = ArrayDotAccess::get($extra, $name, null)) !== null) { |
|
64 | 64 | } elseif (defined($name)) { |
65 | 65 | $value = constant($name); |
66 | 66 | } else { |
67 | 67 | $value = $this->get($name, $matchs[0]); |
68 | 68 | } |
69 | - return is_string($value)?trim(json_encode($value), '"'):$value; |
|
69 | + return is_string($value) ?trim(json_encode($value), '"') : $value; |
|
70 | 70 | }, $content); |
71 | 71 | } |
72 | 72 | } |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | */ |
10 | 10 | abstract class ConfigLoader |
11 | 11 | { |
12 | - public function loadConfig(string $path, array $extra =[]):?array |
|
12 | + public function loadConfig(string $path, array $extra = []): ?array |
|
13 | 13 | { |
14 | - $data=null; |
|
14 | + $data = null; |
|
15 | 15 | if (!file_exists($path)) { |
16 | 16 | $path = static::resolve($path); |
17 | 17 | } |
@@ -27,25 +27,25 @@ discard block |
||
27 | 27 | return $data; |
28 | 28 | } |
29 | 29 | |
30 | - protected function loadJson(string $path, array $extra =[]):array |
|
30 | + protected function loadJson(string $path, array $extra = []):array |
|
31 | 31 | { |
32 | 32 | $content = file_get_contents($path); |
33 | - $content =$this->parseValue($content, $extra); |
|
33 | + $content = $this->parseValue($content, $extra); |
|
34 | 34 | $data = json_decode($content, true); |
35 | - if (json_last_error()!==JSON_ERROR_NONE) { |
|
35 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
36 | 36 | throw new JSONException(json_last_error()); |
37 | 37 | } |
38 | 38 | return $data; |
39 | 39 | } |
40 | 40 | |
41 | - protected function loadIni(string $path, array $extra =[]):array |
|
41 | + protected function loadIni(string $path, array $extra = []):array |
|
42 | 42 | { |
43 | 43 | $content = file_get_contents($path); |
44 | - $content =$this->parseValue($content, $extra); |
|
44 | + $content = $this->parseValue($content, $extra); |
|
45 | 45 | return \parse_ini_string($content, true) ?: []; |
46 | 46 | } |
47 | 47 | |
48 | - protected function loadYaml(string $path, array $extra =[]):array |
|
48 | + protected function loadYaml(string $path, array $extra = []):array |
|
49 | 49 | { |
50 | 50 | if (function_exists('yaml_parse')) { |
51 | 51 | $name = 'yaml_parse'; |
@@ -55,25 +55,25 @@ discard block |
||
55 | 55 | throw new YamlException("parse yaml config error : missing yaml extension or spyc", 1); |
56 | 56 | } |
57 | 57 | $content = file_get_contents($path); |
58 | - $content =$this->parseValue($content, $extra); |
|
58 | + $content = $this->parseValue($content, $extra); |
|
59 | 59 | return \call_user_func_array($name, [$content]); |
60 | 60 | } |
61 | 61 | |
62 | - abstract public function parseValue(string $content, array $extra =[]):string; |
|
62 | + abstract public function parseValue(string $content, array $extra = []):string; |
|
63 | 63 | |
64 | - public static function resolve(string $path):?string |
|
64 | + public static function resolve(string $path): ?string |
|
65 | 65 | { |
66 | 66 | if (file_exists($path)) { |
67 | 67 | return $path; |
68 | 68 | } |
69 | 69 | $basepath = dirname($path).'/'.pathinfo($path, PATHINFO_FILENAME); |
70 | - if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) { |
|
70 | + if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) { |
|
71 | 71 | if (function_exists('yaml_parse') || class_exists('Spyc')) { |
72 | 72 | return $conf; |
73 | 73 | } |
74 | 74 | } |
75 | - foreach (['.json','.php','.ini'] as $ext) { |
|
76 | - if (file_exists($conf=$basepath.$ext)) { |
|
75 | + foreach (['.json', '.php', '.ini'] as $ext) { |
|
76 | + if (file_exists($conf = $basepath.$ext)) { |
|
77 | 77 | return $conf; |
78 | 78 | } |
79 | 79 | } |
@@ -22,9 +22,9 @@ |
||
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
25 | -require_once SUDA_SYSTEM .'/src/component/loader/Path.php'; |
|
26 | -require_once SUDA_SYSTEM .'/src/component/loader/PathTrait.php'; |
|
27 | -require_once SUDA_SYSTEM .'/src/component/loader/PathInterface.php'; |
|
28 | -require_once SUDA_SYSTEM .'/src/component/loader/IncludeManager.php'; |
|
29 | -require_once SUDA_SYSTEM .'/src/component/loader/Loader.php'; |
|
30 | -require_once SUDA_SYSTEM .'/src/application/Loader.php'; |
|
25 | +require_once SUDA_SYSTEM.'/src/component/loader/Path.php'; |
|
26 | +require_once SUDA_SYSTEM.'/src/component/loader/PathTrait.php'; |
|
27 | +require_once SUDA_SYSTEM.'/src/component/loader/PathInterface.php'; |
|
28 | +require_once SUDA_SYSTEM.'/src/component/loader/IncludeManager.php'; |
|
29 | +require_once SUDA_SYSTEM.'/src/component/loader/Loader.php'; |
|
30 | +require_once SUDA_SYSTEM.'/src/application/Loader.php'; |
@@ -4,15 +4,15 @@ |
||
4 | 4 | use suda\application\Loader; |
5 | 5 | use suda\application\Request; |
6 | 6 | |
7 | -require_once __DIR__ .'/loader.php'; |
|
7 | +require_once __DIR__.'/loader.php'; |
|
8 | 8 | |
9 | 9 | |
10 | 10 | |
11 | 11 | // 初始化系统加载器 |
12 | 12 | $loader = new Loader; |
13 | 13 | $loader->register(); |
14 | -$loader->addIncludePath(SUDA_SYSTEM .'/src', 'suda'); |
|
15 | -$loader->import(SUDA_SYSTEM .'/src/functions.php'); |
|
14 | +$loader->addIncludePath(SUDA_SYSTEM.'/src', 'suda'); |
|
15 | +$loader->import(SUDA_SYSTEM.'/src/functions.php'); |
|
16 | 16 | // 初始化请求 |
17 | 17 | $request = Request::buildFromServer(); |
18 | 18 | $request->apply(true); |