Skip to content

Commit

Permalink
add filter manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasfinsight committed Oct 9, 2020
1 parent f40811c commit 2725942
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Registry/ManifestRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,27 @@ public function __construct(iterable $manifests)
/**
* @param AppInterface $app
*
* @param string|null $className
* @return iterable|ManifestInterface[]
*/
public function byApp(AppInterface $app): iterable
public function byApp(AppInterface $app, string $className = null): iterable
{
$reflection = new \ReflectionObject($app);

return $this->byNamespacePrefix($reflection->getNamespaceName());
return $this->byNamespacePrefix($reflection->getNamespaceName(), $className);
}

/**
* @param string $namespacePrefix
*
* @param string|null $className
* @return iterable|ManifestInterface[]
*/
public function byNamespacePrefix(string $namespacePrefix): iterable
public function byNamespacePrefix(string $namespacePrefix, string $className = null): iterable
{
foreach ($this->manifests as $manifest) {
$class = get_class($manifest);
if (str_starts_with($class, $namespacePrefix)) {
if (str_starts_with($class, $namespacePrefix) && (null === $className || $manifest instanceof $className)) {
yield $manifest;
}
}
Expand Down

0 comments on commit 2725942

Please sign in to comment.