@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | $app = $input->getArgument('app'); |
32 | 32 | |
33 | - if (empty($app) && !is_dir($this->app->getBasePath() . 'controller')) { |
|
33 | + if (empty($app) && !is_dir($this->app->getBasePath().'controller')) { |
|
34 | 34 | $output->writeln('<error>Miss app name!</error>'); |
35 | 35 | return false; |
36 | 36 | } |
@@ -47,21 +47,21 @@ discard block |
||
47 | 47 | protected function buildRoute(string $app = null): string |
48 | 48 | { |
49 | 49 | if ($app) { |
50 | - $path = $this->app->getBasePath() . $app . DIRECTORY_SEPARATOR; |
|
51 | - $namespace = 'app\\' . $app; |
|
50 | + $path = $this->app->getBasePath().$app.DIRECTORY_SEPARATOR; |
|
51 | + $namespace = 'app\\'.$app; |
|
52 | 52 | } else { |
53 | 53 | $path = $this->app->getBasePath(); |
54 | 54 | $namespace = 'app'; |
55 | 55 | } |
56 | 56 | |
57 | - $content = '<?php ' . PHP_EOL . '// 根据注解自动生成的路由规则' . PHP_EOL . 'use think\\facade\\Route;' . PHP_EOL; |
|
57 | + $content = '<?php '.PHP_EOL.'// 根据注解自动生成的路由规则'.PHP_EOL.'use think\\facade\\Route;'.PHP_EOL; |
|
58 | 58 | |
59 | 59 | $layer = $this->app->config->get('route.controller_layer'); |
60 | 60 | $suffix = $this->app->config->get('route.controller_suffix'); |
61 | 61 | |
62 | - $content .= $this->buildDirRoute($path . $layer . DIRECTORY_SEPARATOR, $namespace, $suffix, $layer); |
|
62 | + $content .= $this->buildDirRoute($path.$layer.DIRECTORY_SEPARATOR, $namespace, $suffix, $layer); |
|
63 | 63 | |
64 | - $filename = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . ($app ? $app . DIRECTORY_SEPARATOR : '') . 'build_route.php'; |
|
64 | + $filename = $this->app->getRootPath().'runtime'.DIRECTORY_SEPARATOR.($app ? $app.DIRECTORY_SEPARATOR : '').'build_route.php'; |
|
65 | 65 | |
66 | 66 | if (!file_exists($filename)) { |
67 | 67 | touch($filename); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | protected function buildDirRoute(string $path, string $namespace, bool $suffix, string $layer): string |
90 | 90 | { |
91 | 91 | $content = ''; |
92 | - $controllers = glob($path . '*.php'); |
|
92 | + $controllers = glob($path.'*.php'); |
|
93 | 93 | |
94 | 94 | foreach ($controllers as $controller) { |
95 | 95 | $controller = basename($controller, '.php'); |
@@ -99,21 +99,21 @@ discard block |
||
99 | 99 | $controller = substr($controller, 0, -10); |
100 | 100 | } |
101 | 101 | |
102 | - $class = new \ReflectionClass($namespace . '\\' . $layer . '\\' . $controller); |
|
102 | + $class = new \ReflectionClass($namespace.'\\'.$layer.'\\'.$controller); |
|
103 | 103 | |
104 | 104 | if (strpos($layer, '\\')) { |
105 | 105 | // 多级控制器 |
106 | 106 | $level = str_replace(DIRECTORY_SEPARATOR, '.', substr($layer, 11)); |
107 | - $controller = $level . '.' . $controller; |
|
107 | + $controller = $level.'.'.$controller; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | $content .= $this->getControllerRoute($class, $controller); |
111 | 111 | } |
112 | 112 | |
113 | - $subDir = glob($path . '*', GLOB_ONLYDIR); |
|
113 | + $subDir = glob($path.'*', GLOB_ONLYDIR); |
|
114 | 114 | |
115 | 115 | foreach ($subDir as $dir) { |
116 | - $content .= $this->buildDirRoute($dir . DIRECTORY_SEPARATOR, $namespace, $suffix, $layer . '\\' . basename($dir)); |
|
116 | + $content .= $this->buildDirRoute($dir.DIRECTORY_SEPARATOR, $namespace, $suffix, $layer.'\\'.basename($dir)); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return $content; |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | |
134 | 134 | if (false !== strpos($comment, '@route(')) { |
135 | 135 | $comment = $this->parseRouteComment($comment); |
136 | - $comment = preg_replace('/route\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\)/is', 'Route::resource(\1,\'' . $controller . '\')', $comment); |
|
137 | - $content .= PHP_EOL . $comment; |
|
136 | + $comment = preg_replace('/route\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\)/is', 'Route::resource(\1,\''.$controller.'\')', $comment); |
|
137 | + $content .= PHP_EOL.$comment; |
|
138 | 138 | } elseif (false !== strpos($comment, '@group(')) { |
139 | 139 | $comment = $this->parseRouteComment($comment, '@group('); |
140 | 140 | $comment = preg_replace('/group\(\s?([\'\"][\-\_\/\w]+[\'\"])\s?\)/is', 'Route::group(\1)', $comment); |
141 | - $content .= PHP_EOL . $comment; |
|
141 | + $content .= PHP_EOL.$comment; |
|
142 | 142 | preg_match('/group\(\s?[\'\"]([\-\_\/\w]+)[\'\"]\s?\)/is', $comment, $matches); |
143 | 143 | $group = $matches[1]; |
144 | 144 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | foreach ($methods as $method) { |
149 | 149 | $comment = $this->getMethodRouteComment($controller, $method, $group ?? null); |
150 | 150 | if ($comment) { |
151 | - $content .= PHP_EOL . $comment; |
|
151 | + $content .= PHP_EOL.$comment; |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | { |
167 | 167 | $comment = substr($comment, 3, -2); |
168 | 168 | $comment = explode(PHP_EOL, substr(strstr(trim($comment), $tag), 1)); |
169 | - $comment = array_map(function ($item) { |
|
169 | + $comment = array_map(function($item) { |
|
170 | 170 | return trim(trim($item), ' \t*'); |
171 | 171 | }, $comment); |
172 | 172 | |
@@ -175,11 +175,11 @@ discard block |
||
175 | 175 | $comment = array_slice($comment, 0, false === $key ? 1 : $key); |
176 | 176 | } |
177 | 177 | |
178 | - $comment = implode(PHP_EOL . "\t", $comment) . ';'; |
|
178 | + $comment = implode(PHP_EOL."\t", $comment).';'; |
|
179 | 179 | |
180 | 180 | if (strpos($comment, '{')) { |
181 | - $comment = preg_replace_callback('/\{\s?.*?\s?\}/s', function ($matches) { |
|
182 | - return false !== strpos($matches[0], '"') ? '[' . substr(var_export(json_decode($matches[0], true), true), 7, -1) . ']' : $matches[0]; |
|
181 | + $comment = preg_replace_callback('/\{\s?.*?\s?\}/s', function($matches) { |
|
182 | + return false !== strpos($matches[0], '"') ? '['.substr(var_export(json_decode($matches[0], true), true), 7, -1).']' : $matches[0]; |
|
183 | 183 | }, $comment); |
184 | 184 | } |
185 | 185 | return $comment; |
@@ -200,15 +200,15 @@ discard block |
||
200 | 200 | if (false !== strpos($comment, '@route(')) { |
201 | 201 | $comment = $this->parseRouteComment($comment); |
202 | 202 | $action = $reflectMethod->getName(); |
203 | - $group = $group ? '->group(\'' . $group . '\')' : ''; |
|
203 | + $group = $group ? '->group(\''.$group.'\')' : ''; |
|
204 | 204 | |
205 | 205 | if ($suffix = $this->app->route->config('action_suffix')) { |
206 | 206 | $action = substr($action, 0, -strlen($suffix)); |
207 | 207 | } |
208 | 208 | |
209 | - $route = $controller . '/' . $action; |
|
210 | - $comment = preg_replace('/route\s?\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\,?\s?[\'\"]?(\w+?)[\'\"]?\s?\)/is', 'Route::\2(\1,\'' . $route . '\')' . $group, $comment); |
|
211 | - $comment = preg_replace('/route\s?\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\)/is', 'Route::rule(\1,\'' . $route . '\')' . $group, $comment); |
|
209 | + $route = $controller.'/'.$action; |
|
210 | + $comment = preg_replace('/route\s?\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\,?\s?[\'\"]?(\w+?)[\'\"]?\s?\)/is', 'Route::\2(\1,\''.$route.'\')'.$group, $comment); |
|
211 | + $comment = preg_replace('/route\s?\(\s?([\'\"][\-\_\/\:\<\>\?\$\[\]\w]+[\'\"])\s?\)/is', 'Route::rule(\1,\''.$route.'\')'.$group, $comment); |
|
212 | 212 | |
213 | 213 | return $comment; |
214 | 214 | } |