diff --git a/src/Registry/AppRegistry.php b/src/Registry/AppRegistry.php index a0db806..f88d0ae 100644 --- a/src/Registry/AppRegistry.php +++ b/src/Registry/AppRegistry.php @@ -47,6 +47,11 @@ public function has(string $appName): bool public function get(string $appName): AppInterface { + if(!$this->has($appName)) { + throw new \InvalidArgumentException( + sprintf('App "%s" does not exist', $appName) + ); + } return $this->apps[$appName]; } } diff --git a/src/Registry/ManifestRegistry.php b/src/Registry/ManifestRegistry.php index ac3e938..36fd469 100644 --- a/src/Registry/ManifestRegistry.php +++ b/src/Registry/ManifestRegistry.php @@ -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; } } diff --git a/src/Registry/ProjectRegistry.php b/src/Registry/ProjectRegistry.php index 3e1b1fa..1b4e9a3 100644 --- a/src/Registry/ProjectRegistry.php +++ b/src/Registry/ProjectRegistry.php @@ -51,6 +51,11 @@ public function has(string $projectName): bool public function get(string $projectName): ProjectInterface { + if(!$this->has($projectName)) { + throw new \InvalidArgumentException( + sprintf('Project "%s" does not exist', $projectName) + ); + } return $this->projects[$projectName]; } }