From 9e13a9c937e19b127b67b8d4ea5f685cbeac0e1e Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Fri, 11 Sep 2020 18:19:06 +0800 Subject: [PATCH] =?UTF-8?q?upadte:=E4=BC=98=E5=8C=96=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/command/TestCommand.php | 10 +++++ extend/catcher/command/stubs/command.stub | 10 +++++ extend/catcher/command/stubs/controller.stub | 10 +++++ extend/catcher/command/stubs/event.stub | 10 +++++ extend/catcher/command/stubs/migrate.stub | 9 ++++ extend/catcher/command/stubs/migration.stub | 9 ++++ .../catcher/command/stubs/permissionSeed.stub | 9 ++++ extend/catcher/command/stubs/request.stub | 10 +++++ extend/catcher/command/stubs/route.stub | 14 ++++-- extend/catcher/command/stubs/seed.stub | 9 ++++ extend/catcher/command/stubs/seeder.stub | 9 ++++ extend/catcher/command/stubs/service.stub | 10 +++++ extend/catcher/generate/factory/Route.php | 44 +++++++++++++++++-- 13 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 extend/catcher/command/TestCommand.php diff --git a/extend/catcher/command/TestCommand.php b/extend/catcher/command/TestCommand.php new file mode 100644 index 0000000..ef90e0a --- /dev/null +++ b/extend/catcher/command/TestCommand.php @@ -0,0 +1,10 @@ +group(function () use ($router){ - -}); +})->middleware('auth'); diff --git a/extend/catcher/command/stubs/seed.stub b/extend/catcher/command/stubs/seed.stub index 8e1fa03..035c561 100644 --- a/extend/catcher/command/stubs/seed.stub +++ b/extend/catcher/command/stubs/seed.stub @@ -1,4 +1,13 @@ restful) { - $route[] = sprintf("\$router->resource('%s', '\%s')->middleware('auth')", $this->controllerName, $this->controller); + $route[] = sprintf("\$router->resource('%s', '\%s');", $this->controllerName, $this->controller); } if (!empty($this->methods)) { foreach ($this->methods as $method) { - $route[] = sprintf("\$router->%s('%s/%s', '\%s@%s')->middleware('auth')", $method[1], $this->controllerName, $method[0], $this->controller, $method[0] ); + $route[] = sprintf("\$router->%s('%s/%s', '\%s@%s');", $method[1], $this->controllerName, $method[0], $this->controller, $method[0] ); } } $router = $this->getModulePath($this->controller) . DIRECTORY_SEPARATOR . 'route.php'; - $comment = PHP_EOL . '//' . $this->controllerName . '路由' . PHP_EOL; + $comment = '// ' . $this->controllerName . '路由'; + array_unshift($route, $comment); if (file_exists($router)) { - return file_put_contents($router, PHP_EOL . $comment . implode(';'. PHP_EOL , $route) . ';', FILE_APPEND); + return file_put_contents($router, $this->parseRoute($router, $route)); } return file_put_contents($router, $this->header() . $comment. implode(';'. PHP_EOL , $route) . ';'); } + protected function parseRoute($path, $route) + { + $file = new \SplFileObject($path); + // 保留所有行 + $lines = []; + // 结尾之后的数据 + $down = []; + // 结尾数据 + $end = ''; + while (!$file->eof()) { + $lines[] = rtrim($file->current(), PHP_EOL); + $file->next(); + } + + while (count($lines)) { + $line = array_pop($lines); + if (strpos($line, '})') !== false) { + $end = $line; + break; + } + array_unshift($down, $line); + } + + $router = implode(PHP_EOL, $lines) . PHP_EOL; + + $routes = array_merge($down, $route); + + foreach ($routes as $r) { + if ($r) { + $router .= "\t" . $r . PHP_EOL; + } + } + return $router .= $end; + } + /** * set class *