Skip to content

Commit

Permalink
Merge pull request #1 from dealroadshow/taral-fix-feature
Browse files Browse the repository at this point in the history
Add second params to `ManifestRegistry` methods
  • Loading branch information
petr-buchyn authored Oct 9, 2020
2 parents f40811c + 5f1f05f commit 6c34023
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/Registry/AppRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
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
5 changes: 5 additions & 0 deletions src/Registry/ProjectRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

0 comments on commit 6c34023

Please sign in to comment.