Factory Implementation
This commit is contained in:
46
src/Implement/Model/Factory.php
Normal file
46
src/Implement/Model/Factory.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProVM\Implement\Model;
|
||||||
|
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
use ProVM\Concept\Model\Factory as FactoryInterface;
|
||||||
|
use ProVM\Concept\Model\Repository;
|
||||||
|
|
||||||
|
class Factory implements FactoryInterface
|
||||||
|
{
|
||||||
|
public function __construct(ContainerInterface $container)
|
||||||
|
{
|
||||||
|
$this->setContainer($container);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ContainerInterface $container;
|
||||||
|
public function setContainer(ContainerInterface $container): FactoryInterface
|
||||||
|
{
|
||||||
|
$this->container = $container;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getContainer(): ContainerInterface
|
||||||
|
{
|
||||||
|
return $this->container;
|
||||||
|
}
|
||||||
|
protected string $namespace;
|
||||||
|
public function setNamespace(string $namespace): FactoryInterface
|
||||||
|
{
|
||||||
|
$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));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user