From 2725942d14c8de72a020ec70e3215fc6bd9bef58 Mon Sep 17 00:00:00 2001 From: Pasechnik Bogdan Date: Fri, 9 Oct 2020 10:57:29 +0300 Subject: [PATCH 1/2] add filter manifests --- src/Registry/ManifestRegistry.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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; } } From 5f1f05fbe6b9bf8e0735f62915ff74566a55c266 Mon Sep 17 00:00:00 2001 From: Pasechnik Bogdan Date: Fri, 9 Oct 2020 12:38:39 +0300 Subject: [PATCH 2/2] add exception if app or project not found --- src/Registry/AppRegistry.php | 5 +++++ src/Registry/ProjectRegistry.php | 5 +++++ 2 files changed, 10 insertions(+) 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/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]; } }