完善打包和打包后的节点更新逻辑;

This commit is contained in:
2022-11-19 15:25:45 +08:00
parent a432778cd3
commit 67a3d287ad
3 changed files with 53 additions and 11 deletions

View File

@@ -23,4 +23,4 @@ class NodeService
->getNodelist();
return $nodeList;
}
}
}

View File

@@ -58,6 +58,8 @@ class Node
*/
public function getNodelist()
{
list($nodeList, $controllerList) = [[], $this->getControllerList()];
if (!empty($controllerList)) {
@@ -70,7 +72,7 @@ class Node
// 获取类和方法的注释信息
$reflectionClass = new \ReflectionClass($controller);
$methods = $reflectionClass->getMethods();
$actionList = [];
@@ -109,13 +111,46 @@ class Node
return $nodeList;
}
public function getAllControllerClass()
{
$namespace = $this->baseNamespace;
$myClasses = array_filter(get_declared_classes(), function ($item) use ($namespace) {
return substr($item, 0, strlen($namespace)) === $namespace;
});
$theClasses = [];
foreach ($myClasses as $class) :
$theClasses[] = $class;
endforeach;
return $theClasses;
}
/**
* 获取所有控制器
* @return array
*/
public function getControllerList()
{
return $this->readControllerFiles($this->basePath);
$list = [];
if (defined('ULTHON_ADMIN_BUILD_DIST')) {
$list = $this->getAllControllerClass();
} else {
$list = $this->readControllerFiles($this->basePath);
}
$target_list = [];
foreach ($list as $class_name) {
$class_name_main = str_replace($this->baseNamespace . '\\', '', $class_name);
$controller_format = str_replace('\\', '.', $class_name_main);
$target_list[$controller_format] = $class_name;
}
return $target_list;
}
/**
@@ -123,13 +158,14 @@ class Node
* @param $path
* @return array
*/
protected function readControllerFiles($path)
protected function readControllerFiles($path = null)
{
list($list, $temp_list, $dirExplode) = [[], scandir($path), explode($this->basePath, $path)];
$temp_list = scandir($path);
$dirExplode = explode($this->basePath, $path);
$middleDir = isset($dirExplode[1]) && !empty($dirExplode[1]) ? str_replace('/', '\\', substr($dirExplode[1], 1)) . "\\" : '';
$list = [];
foreach ($temp_list as $file) {
// 排除根目录和没有开启注解的模块
if ($file == ".." || $file == ".") {
@@ -147,10 +183,8 @@ class Node
}
// 根目录下的文件
$className = str_replace('.php', '', $file);
$controllerFormat = str_replace('\\', '.', $middleDir) . Str::snake(lcfirst($className));
$list[$controllerFormat] = "{$this->baseNamespace}\\{$middleDir}" . $className;
$list[] = $this->baseNamespace . '\\' . $middleDir . $className;
}
}

View File

@@ -325,6 +325,14 @@ class Dist extends Command
{
$file_stmts = [];
$file_stmts[] = new Expression(new FuncCall(
new Name('define'),
[
new Arg(new String_('ULTHON_ADMIN_BUILD_DIST')),
new Arg(new String_('1'))
]
));
foreach ($files as $file_name) {
$file_stmts[] = new Expression(new Include_(new Concat(new Dir, new String_($file_name)), Include_::TYPE_REQUIRE_ONCE));
}
@@ -505,7 +513,7 @@ class Dist extends Command
*
* @param Node\Stmt[]|null $stmts
* @param string $name
* @return void
* @return Node\Stmt[]
*/
public function parseStmts($stmts, $name)
{