Use full class name without having to specify namespace beforehand
This commit is contained in:
@ -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;
|
|
||||||
}
|
}
|
||||||
|
@ -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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user