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
+56 -42
View File
@@ -7,60 +7,74 @@ namespace Annotation;
class FileTree class FileTree
{ {
private array $files = []; private array $files = [];
private array $childes = []; private array $childes = [];
/** private string $_filePath = '';
* @param $path
* @return $this|null
*/
public function getChild($path): ?static
{
if (!isset($this->childes[$path])) {
$this->addChild($path, new FileTree());
}
return $this->childes[$path];
}
/** /**
* @param string $path * @param $path
* @param FileTree $fileTree * @return $this|null
*/ */
public function addChild(string $path, FileTree $fileTree) public function getChild($path): ?static
{ {
$this->childes[$path] = $fileTree; if (!isset($this->childes[$path])) {
} $this->addChild($path, new FileTree());
}
return $this->childes[$path];
}
/** /**
* @param string $className * @param string $path
*/ * @param FileTree $fileTree
public function addFile(string $className) */
{ public function addChild(string $path, FileTree $fileTree)
$this->files[] = $className; {
} $this->childes[$path] = $fileTree;
}
/** /**
* @return array * @param string $className
*/ * @param string $path
public function getFiles(): array */
{ public function addFile(string $className, string $path)
return $this->files; {
} $this->files[] = $className;
$this->_filePath = $path;
}
/** /**
* @return array * @return array
*/ */
public function getChildes(): array public function getFiles(): array
{ {
return $this->childes; return $this->files;
} }
/**
* @return string
*/
public function getDirPath(): string
{
return $this->_filePath;
}
/**
* @return array
*/
public function getChildes(): array
{
return $this->childes;
}
} }
+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());
} }
} }