mirror of https://gitee.com/karson/fastadmin.git
parent
a5355f4d5d
commit
5e7a598a19
|
|
@ -55,15 +55,15 @@ class Crud extends Command
|
||||||
$tableInfo = $tableInfo[0];
|
$tableInfo = $tableInfo[0];
|
||||||
|
|
||||||
//根据表名匹配对应的Fontawesome图标
|
//根据表名匹配对应的Fontawesome图标
|
||||||
$iconPath = ROOT_PATH . '/public/assets/libs/font-awesome/less/variables.less';
|
$iconPath = ROOT_PATH . str_replace('/', DS, '/public/assets/libs/font-awesome/less/variables.less');
|
||||||
$iconName = is_file($iconPath) && stripos(file_get_contents($iconPath), '@fa-var-' . $table . ':') ? $table : 'fa fa-circle-o';
|
$iconName = is_file($iconPath) && stripos(file_get_contents($iconPath), '@fa-var-' . $table . ':') ? $table : 'fa fa-circle-o';
|
||||||
|
|
||||||
//控制器默认以表名进行处理,以下划线进行分隔,如果需要自定义则需要传入controller,格式为目录层级
|
//控制器默认以表名进行处理,以下划线进行分隔,如果需要自定义则需要传入controller,格式为目录层级
|
||||||
$controllerArr = !$controller ? explode('_', strtolower($table)) : explode('/', strtolower($controller));
|
$controllerArr = !$controller ? explode('_', strtolower($table)) : explode('/', strtolower($controller));
|
||||||
$controllerUrl = implode('/', $controllerArr);
|
$controllerUrl = implode('/', $controllerArr);
|
||||||
$controllerName = ucfirst(array_pop($controllerArr));
|
$controllerName = ucfirst(array_pop($controllerArr));
|
||||||
$controllerDir = implode('/', $controllerArr);
|
$controllerDir = implode(DS, $controllerArr);
|
||||||
$controllerFile = ($controllerDir ? $controllerDir . '/' : '') . $controllerName . '.php';
|
$controllerFile = ($controllerDir ? $controllerDir . DS : '') . $controllerName . '.php';
|
||||||
|
|
||||||
//非覆盖模式时如果存在控制器文件则报错
|
//非覆盖模式时如果存在控制器文件则报错
|
||||||
if (is_file($controllerFile) && !$force)
|
if (is_file($controllerFile) && !$force)
|
||||||
|
|
@ -330,7 +330,7 @@ class Crud extends Command
|
||||||
*/
|
*/
|
||||||
protected function getStub($name)
|
protected function getStub($name)
|
||||||
{
|
{
|
||||||
return __DIR__ . '/Crud/stubs/' . $name . '.stub';
|
return __DIR__ . DS . 'Crud' . DS . 'stubs' . DS . $name . '.stub';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getLangItem($field, $content)
|
protected function getLangItem($field, $content)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class Menu extends Command
|
||||||
end($controllerArr);
|
end($controllerArr);
|
||||||
$key = key($controllerArr);
|
$key = key($controllerArr);
|
||||||
$controllerArr[$key] = ucfirst($controllerArr[$key]);
|
$controllerArr[$key] = ucfirst($controllerArr[$key]);
|
||||||
$adminPath = dirname(__DIR__) . DS . 'controller' . DS . implode('/', $controllerArr) . '.php';
|
$adminPath = dirname(__DIR__) . DS . 'controller' . DS . implode(DS, $controllerArr) . '.php';
|
||||||
if (!is_file($adminPath))
|
if (!is_file($adminPath))
|
||||||
{
|
{
|
||||||
$output->error("controller not found");
|
$output->error("controller not found");
|
||||||
|
|
@ -75,9 +75,9 @@ class Menu extends Command
|
||||||
{
|
{
|
||||||
if (!in_array($value, array(".", "..")))
|
if (!in_array($value, array(".", "..")))
|
||||||
{
|
{
|
||||||
if (is_dir($dir . '/' . $value))
|
if (is_dir($dir . DS . $value))
|
||||||
{
|
{
|
||||||
$result[$value] = $this->scandir($dir . '/' . $value);
|
$result[$value] = $this->scandir($dir . DS . $value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -127,8 +127,32 @@ class Menu extends Command
|
||||||
end($controllerArr);
|
end($controllerArr);
|
||||||
$key = key($controllerArr);
|
$key = key($controllerArr);
|
||||||
$controllerArr[$key] = ucfirst($controllerArr[$key]);
|
$controllerArr[$key] = ucfirst($controllerArr[$key]);
|
||||||
|
$classSuffix = Config::get('controller_suffix') ? ucfirst(Config::get('url_controller_layer')) : '';
|
||||||
|
$className = "\\app\\admin\\controller\\" . implode("\\", $controllerArr) . $classSuffix;
|
||||||
|
if (version_compare(PHP_VERSION, '7.0.0', '<'))
|
||||||
|
{
|
||||||
|
$pathArr = $controllerArr;
|
||||||
|
array_unshift($pathArr, '', 'application', 'admin', 'controller');
|
||||||
|
$classFile = ROOT_PATH . implode(DS, $pathArr) . $classSuffix . ".php";
|
||||||
|
$classContent = file_get_contents($classFile);
|
||||||
|
$uniqueName = uniqid("FastAdmin") . $classSuffix;
|
||||||
|
$classContent = str_replace("class " . $controllerArr[$key] . $classSuffix . " ", 'class ' . $uniqueName . ' ', $classContent);
|
||||||
|
$classContent = preg_replace("/namespace\s(.*);/", 'namespace ' . __NAMESPACE__ . ";", $classContent);
|
||||||
|
|
||||||
|
//临时的类文件
|
||||||
|
$tempClassFile = __DIR__ . DS . $uniqueName . ".php";
|
||||||
|
file_put_contents($tempClassFile, $classContent);
|
||||||
|
$className = "\\app\\admin\\command\\" . $uniqueName;
|
||||||
|
}
|
||||||
//反射机制调用类的注释和方法名
|
//反射机制调用类的注释和方法名
|
||||||
$reflector = new ReflectionClass("\\app\\admin\\controller\\" . implode("\\", $controllerArr) . (Config::get('controller_suffix') ? ucfirst(Config::get('url_controller_layer')) : ''));
|
$reflector = new ReflectionClass($className);
|
||||||
|
|
||||||
|
if (isset($tempClassFile))
|
||||||
|
{
|
||||||
|
//删除临时文件
|
||||||
|
@unlink($tempClassFile);
|
||||||
|
}
|
||||||
|
|
||||||
//只匹配公共的方法
|
//只匹配公共的方法
|
||||||
$methods = $reflector->getMethods(ReflectionMethod::IS_PUBLIC);
|
$methods = $reflector->getMethods(ReflectionMethod::IS_PUBLIC);
|
||||||
$classComment = $reflector->getDocComment();
|
$classComment = $reflector->getDocComment();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue