diff --git a/CHANGELOG.md b/CHANGELOG.md index ed35b1a..fb62d8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* Fixed Generic Resolver class scanner +* Added namespace map filter check + ## v0.3.1 (2024-04-26) * Fixed namespaceMap accessor diff --git a/src/NamespaceList.php b/src/NamespaceList.php index 1875036..24174a3 100644 --- a/src/NamespaceList.php +++ b/src/NamespaceList.php @@ -67,8 +67,16 @@ public function remove( public function import( NamespaceList $list, ?string $mapTo = null, + ?string $filter = null ): void { foreach ($list->namespaces as $namespace => $priority) { + if ( + $filter !== null && + str_starts_with($filter, $namespace) + ) { + continue; + } + if ($mapTo !== null) { $namespace .= '\\' . $mapTo; } diff --git a/src/NamespaceMap.php b/src/NamespaceMap.php index 24ff328..13972cf 100644 --- a/src/NamespaceMap.php +++ b/src/NamespaceMap.php @@ -130,7 +130,7 @@ protected function applyMap( if (isset($this->namespaces[$root])) { $mapTo = empty($inner) ? null : implode('\\', $inner); - $namespaces->import($this->namespaces[$root], $mapTo); + $namespaces->import($this->namespaces[$root], $mapTo, $namespace); } array_unshift($inner, array_pop($parts)); diff --git a/src/Resolver/Generic.php b/src/Resolver/Generic.php index 73098db..c87823e 100644 --- a/src/Resolver/Generic.php +++ b/src/Resolver/Generic.php @@ -24,8 +24,6 @@ class Generic implements Scanner, DefaultName */ protected string $interface; - protected NamespaceList $namespaceList; - /** * Init with interface @@ -36,7 +34,6 @@ public function __construct( string $interface ) { $this->interface = $interface; - $this->namespaceList = new NamespaceList(); } /** @@ -55,16 +52,6 @@ public function getPriority(): int return 20; } - /** - * Add namespace - */ - public function addNamespace( - string $namespace, - int $priority = 0 - ): void { - $this->namespaceList->add($namespace, $priority); - } - /** * Resolve Archetype class location */ @@ -91,9 +78,7 @@ public function resolve( */ public function scanClasses(): Generator { - yield from $this->scanNamespaceClasses($this->interface); - - foreach ($this->namespaceList as $namespace) { + foreach ($this->namespaces->map($this->interface) as $namespace) { yield from $this->scanNamespaceClasses($namespace, $this->interface); } }