upadte:优化路由写入
This commit is contained in:
parent
90990f8782
commit
9e13a9c937
10
extend/catcher/command/TestCommand.php
Normal file
10
extend/catcher/command/TestCommand.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace {NAMESPACE};
|
||||
|
||||
use think\console\Command;
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace {NAMESPACE};
|
||||
|
||||
use catcher\base\CatchController;
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace {NAMESPACE};
|
||||
|
@ -1,4 +1,13 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
|
@ -1,4 +1,13 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\migration\Migrator;
|
||||
use think\migration\db\Column;
|
||||
|
@ -1,4 +1,13 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\migration\Seeder;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace {NAMESPACE};
|
||||
|
||||
use catcher\base\CatchRequest;
|
||||
|
@ -1,7 +1,15 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// you should user `$router`
|
||||
// you should use `$router`
|
||||
$router->group(function () use ($router){
|
||||
|
||||
});
|
||||
})->middleware('auth');
|
||||
|
||||
|
@ -1,4 +1,13 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\migration\Seeder;
|
||||
|
||||
|
@ -1,4 +1,13 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
use think\migration\Seeder;
|
||||
|
||||
|
@ -1,4 +1,14 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CatchAdmin [Just Like ~ ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace {NAMESPACE};
|
||||
|
||||
use catcher\ModuleService;
|
||||
|
@ -20,26 +20,62 @@ class Route extends Factory
|
||||
$route = [];
|
||||
|
||||
if ($this->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
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user