Use full class name without having to specify namespace beforehand

This commit is contained in:
2022-09-09 13:15:11 -04:00
parent 55275d2d75
commit 9834eb70a4
2 changed files with 3 additions and 22 deletions

View File

@ -7,7 +7,5 @@ interface Factory
{ {
public function setContainer(ContainerInterface $container): Factory; public function setContainer(ContainerInterface $container): Factory;
public function getContainer(): ContainerInterface; public function getContainer(): ContainerInterface;
public function setNamespace(string $namespace): Factory; public function get(string $repository_class): Repository;
public function getNamespace(): string;
public function get(string $repository_name): Repository;
} }

View File

@ -22,25 +22,8 @@ class Factory implements FactoryInterface
{ {
return $this->container; return $this->container;
} }
protected string $namespace; public function get(string $repository_class): Repository
public function setNamespace(string $namespace): FactoryInterface
{ {
$this->namespace = $namespace; return $this->getContainer()->get($repository_class);
return $this;
}
public function getNamespace(): string
{
return $this->namespace;
}
protected function buildRepository(string $repository_name): string
{
return implode("\\", [
$this->getNamespace(),
$repository_name
]);
}
public function get(string $repository_name): Repository
{
return $this->getContainer()->get($this->buildRepository($repository_name));
} }
} }