Skip to content

Commit

Permalink
Merge branch 'release/v0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Apr 29, 2024
2 parents 6688a34 + b427bea commit 0cd3bd8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.3.2 (2024-04-29)
* Fixed Generic Resolver class scanner
* Added namespace map filter check

## v0.3.1 (2024-04-26)
* Fixed namespaceMap accessor

Expand Down
8 changes: 8 additions & 0 deletions src/NamespaceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/NamespaceMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
17 changes: 1 addition & 16 deletions src/Resolver/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class Generic implements Scanner, DefaultName
*/
protected string $interface;

protected NamespaceList $namespaceList;


/**
* Init with interface
Expand All @@ -36,7 +34,6 @@ public function __construct(
string $interface
) {
$this->interface = $interface;
$this->namespaceList = new NamespaceList();
}

/**
Expand All @@ -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
*/
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 0cd3bd8

Please sign in to comment.