This commit is contained in:
2021-04-14 18:22:55 +08:00
parent 74858dc46b
commit e8282b8862
2 changed files with 65 additions and 50 deletions
+15 -1
View File
@@ -13,6 +13,9 @@ class FileTree
private array $childes = []; private array $childes = [];
private string $_filePath = '';
/** /**
* @param $path * @param $path
* @return $this|null * @return $this|null
@@ -38,10 +41,12 @@ class FileTree
/** /**
* @param string $className * @param string $className
* @param string $path
*/ */
public function addFile(string $className) public function addFile(string $className, string $path)
{ {
$this->files[] = $className; $this->files[] = $className;
$this->_filePath = $path;
} }
@@ -54,6 +59,15 @@ class FileTree
} }
/**
* @return string
*/
public function getDirPath(): string
{
return $this->_filePath;
}
/** /**
* @return array * @return array
*/ */
+9 -8
View File
@@ -251,7 +251,7 @@ class Loader extends BaseObject
} }
if ($tree instanceof FileTree) { if ($tree instanceof FileTree) {
$tree->addFile($className); $tree->addFile($className, $filePath);
} }
} }
@@ -270,19 +270,17 @@ class Loader extends BaseObject
$_tmp = ''; $_tmp = '';
if (!empty($outPath)) { if (!empty($outPath)) {
$outPath = rtrim($outPath, '/'); $outPath = rtrim($outPath, '/');
$this->addError($_tmp . '-->' . $outPath);
} }
foreach ($directory as $key => $value) { foreach ($directory as $key => $value) {
$_tmp .= DIRECTORY_SEPARATOR . $value; $_tmp .= DIRECTORY_SEPARATOR . $value;
$this->addError($_tmp);
if (!empty($outPath) && str_contains($_tmp, $outPath)) { if (!empty($outPath) && str_contains($_tmp, $outPath)) {
break; break;
} }
$tree = $this->getTree($tree, $value); $tree = $this->getTree($tree, $value);
} }
if ($tree instanceof FileTree) { if ($tree instanceof FileTree) {
$this->eachNode($tree->getChildes()); $this->eachNode($tree->getChildes(), $outPath);
$this->execute($tree->getFiles()); $this->execute($tree->getFiles());
} }
return $this; return $this;
@@ -320,16 +318,19 @@ class Loader extends BaseObject
/** /**
* @param FileTree[] $nodes * @param FileTree[] $nodes
* @param string|null $outPath
*/ */
private function eachNode(array $nodes) private function eachNode(array $nodes, ?string $outPath = '')
{ {
foreach ($nodes as $node) { foreach ($nodes as $node) {
$this->execute($node->getFiles());
if (!empty($outPaht) && str_contains($node->getDirPath(), $outPath)) {
continue;
}
$childes = $node->getChildes(); $childes = $node->getChildes();
if (!empty($childes)) { if (!empty($childes)) {
var_dump($childes); $this->eachNode($childes, $outPath);
$this->eachNode($childes);
} }
$this->execute($node->getFiles());
} }
} }