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 getContainer(): ContainerInterface;
|
||||
public function setNamespace(string $namespace): Factory;
|
||||
public function getNamespace(): string;
|
||||
public function get(string $repository_name): Repository;
|
||||
public function get(string $repository_class): Repository;
|
||||
}
|
||||
|
@ -22,25 +22,8 @@ class Factory implements FactoryInterface
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
protected string $namespace;
|
||||
public function setNamespace(string $namespace): FactoryInterface
|
||||
public function get(string $repository_class): Repository
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
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));
|
||||
return $this->getContainer()->get($repository_class);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user