diff --git a/Annotation/Annotation.php b/Annotation/Annotation.php index 0096de9f..08a6ba98 100644 --- a/Annotation/Annotation.php +++ b/Annotation/Annotation.php @@ -8,7 +8,6 @@ use DirectoryIterator; use Exception; use ReflectionException; use Snowflake\Abstracts\Component; -use Snowflake\Exception\NotFindClassException; /** * Class Annotation @@ -179,13 +178,13 @@ class Annotation extends Component /** * @param string $path * @param string $namespace - * @param string $alias + * @param array $exclude * @return void * @throws Exception */ - public function read(string $path, string $namespace = 'App', string $alias = 'root'): void + public function read(string $path, string $namespace = 'App', array $exclude = []): void { - $this->_loader->_scanDir(new DirectoryIterator($path), $namespace); + $this->_loader->_scanDir(new DirectoryIterator($path), $namespace, $exclude); } diff --git a/Annotation/Loader.php b/Annotation/Loader.php index bab673e6..12446c14 100644 --- a/Annotation/Loader.php +++ b/Annotation/Loader.php @@ -95,14 +95,18 @@ class Loader extends BaseObject /** * @param DirectoryIterator $paths * @param $namespace + * @param array $exclude * @throws Exception */ - public function _scanDir(DirectoryIterator $paths, $namespace) + public function _scanDir(DirectoryIterator $paths, $namespace, array $exclude = []) { foreach ($paths as $path) { if ($path->isDot() || str_starts_with($path->getFilename(), '.')) { continue; } + if ($this->inExclude($exclude, $path->getRealPath())) { + continue; + } if ($path->isDir()) { $iterator = new DirectoryIterator($path->getRealPath()); $directory = rtrim($path->getRealPath(), '/'); diff --git a/function.php b/function.php index 409321b1..01ec4442 100644 --- a/function.php +++ b/function.php @@ -98,7 +98,7 @@ if (!function_exists('scan_directory')) { function scan_directory($dir, $namespace, array $exclude = []) { $annotation = Snowflake::app()->getAnnotation(); - $annotation->read($dir, $namespace); + $annotation->read($dir, $namespace, $exclude); injectRuntime($dir, $exclude); }