From 5e7a598a193294d9b745a985c8c99ca184433a69 Mon Sep 17 00:00:00 2001 From: Karson Date: Sun, 7 May 2017 13:52:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E9=94=AE=E7=94=9F?= =?UTF-8?q?=E6=88=90CRUD=E7=9A=84=E7=9B=AE=E5=BD=95=E8=B7=AF=E5=BE=84=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E9=94=AE=E7=94=9F=E6=88=90=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=9C=A8php7.0=E7=89=88=E6=9C=AC=E4=B8=8B=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E4=B8=80=E9=94=AE=E7=94=9F=E6=88=90=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Crud.php | 8 ++++---- application/admin/command/Menu.php | 32 ++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php index ade0a9a5..198b0ffa 100644 --- a/application/admin/command/Crud.php +++ b/application/admin/command/Crud.php @@ -55,15 +55,15 @@ class Crud extends Command $tableInfo = $tableInfo[0]; //根据表名匹配对应的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'; //控制器默认以表名进行处理,以下划线进行分隔,如果需要自定义则需要传入controller,格式为目录层级 $controllerArr = !$controller ? explode('_', strtolower($table)) : explode('/', strtolower($controller)); $controllerUrl = implode('/', $controllerArr); $controllerName = ucfirst(array_pop($controllerArr)); - $controllerDir = implode('/', $controllerArr); - $controllerFile = ($controllerDir ? $controllerDir . '/' : '') . $controllerName . '.php'; + $controllerDir = implode(DS, $controllerArr); + $controllerFile = ($controllerDir ? $controllerDir . DS : '') . $controllerName . '.php'; //非覆盖模式时如果存在控制器文件则报错 if (is_file($controllerFile) && !$force) @@ -330,7 +330,7 @@ class Crud extends Command */ protected function getStub($name) { - return __DIR__ . '/Crud/stubs/' . $name . '.stub'; + return __DIR__ . DS . 'Crud' . DS . 'stubs' . DS . $name . '.stub'; } protected function getLangItem($field, $content) diff --git a/application/admin/command/Menu.php b/application/admin/command/Menu.php index d50609e5..888eb283 100644 --- a/application/admin/command/Menu.php +++ b/application/admin/command/Menu.php @@ -43,7 +43,7 @@ class Menu extends Command end($controllerArr); $key = key($controllerArr); $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)) { $output->error("controller not found"); @@ -75,9 +75,9 @@ class Menu extends Command { 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 { @@ -127,8 +127,32 @@ class Menu extends Command end($controllerArr); $key = key($controllerArr); $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); $classComment = $reflector->getDocComment();