diff --git a/Annotation/FileTree.php b/Annotation/FileTree.php index 36cb1332..4474fe5f 100644 --- a/Annotation/FileTree.php +++ b/Annotation/FileTree.php @@ -7,60 +7,74 @@ namespace Annotation; class FileTree { - private array $files = []; + private array $files = []; - private array $childes = []; + private array $childes = []; - /** - * @param $path - * @return $this|null - */ - public function getChild($path): ?static - { - if (!isset($this->childes[$path])) { - $this->addChild($path, new FileTree()); - } - return $this->childes[$path]; - } + private string $_filePath = ''; - /** - * @param string $path - * @param FileTree $fileTree - */ - public function addChild(string $path, FileTree $fileTree) - { - $this->childes[$path] = $fileTree; - } + /** + * @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 $className - */ - public function addFile(string $className) - { - $this->files[] = $className; - } + /** + * @param string $path + * @param FileTree $fileTree + */ + public function addChild(string $path, FileTree $fileTree) + { + $this->childes[$path] = $fileTree; + } - /** - * @return array - */ - public function getFiles(): array - { - return $this->files; - } + /** + * @param string $className + * @param string $path + */ + public function addFile(string $className, string $path) + { + $this->files[] = $className; + $this->_filePath = $path; + } - /** - * @return array - */ - public function getChildes(): array - { - return $this->childes; - } + /** + * @return array + */ + public function getFiles(): array + { + return $this->files; + } + + + /** + * @return string + */ + public function getDirPath(): string + { + return $this->_filePath; + } + + + /** + * @return array + */ + public function getChildes(): array + { + return $this->childes; + } } diff --git a/Annotation/Loader.php b/Annotation/Loader.php index 375bd84c..b342e249 100644 --- a/Annotation/Loader.php +++ b/Annotation/Loader.php @@ -251,7 +251,7 @@ class Loader extends BaseObject } if ($tree instanceof FileTree) { - $tree->addFile($className); + $tree->addFile($className, $filePath); } } @@ -270,19 +270,17 @@ class Loader extends BaseObject $_tmp = ''; if (!empty($outPath)) { $outPath = rtrim($outPath, '/'); - $this->addError($_tmp . '-->' . $outPath); } foreach ($directory as $key => $value) { $_tmp .= DIRECTORY_SEPARATOR . $value; - $this->addError($_tmp); if (!empty($outPath) && str_contains($_tmp, $outPath)) { break; } $tree = $this->getTree($tree, $value); } if ($tree instanceof FileTree) { - $this->eachNode($tree->getChildes()); + $this->eachNode($tree->getChildes(), $outPath); $this->execute($tree->getFiles()); } return $this; @@ -320,16 +318,19 @@ class Loader extends BaseObject /** * @param FileTree[] $nodes + * @param string|null $outPath */ - private function eachNode(array $nodes) + private function eachNode(array $nodes, ?string $outPath = '') { foreach ($nodes as $node) { + $this->execute($node->getFiles()); + if (!empty($outPaht) && str_contains($node->getDirPath(), $outPath)) { + continue; + } $childes = $node->getChildes(); if (!empty($childes)) { - var_dump($childes); - $this->eachNode($childes); + $this->eachNode($childes, $outPath); } - $this->execute($node->getFiles()); } }