27 lines
754 B
PHP
27 lines
754 B
PHP
|
<?php
|
||
|
namespace Common\Alias\Factory;
|
||
|
|
||
|
use Common\Concept\Factory\Model as FactoryInterface;
|
||
|
use Common\Concept\Model as ModelInterface;
|
||
|
use Common\Concept\Repository;
|
||
|
use Psr\Container\ContainerInterface;
|
||
|
|
||
|
abstract class Model implements FactoryInterface
|
||
|
{
|
||
|
protected ContainerInterface $container;
|
||
|
public function setContainer(ContainerInterface $container): Model
|
||
|
{
|
||
|
$this->container = $container;
|
||
|
return $this;
|
||
|
}
|
||
|
public function getContainer(): ContainerInterface
|
||
|
{
|
||
|
return $this->container;
|
||
|
}
|
||
|
public function find(ModelInterface $model_name): Repository
|
||
|
{
|
||
|
$class = str_replace('Model', 'Repository', get_class($model_name));
|
||
|
return $this->getContainer()->get($class);
|
||
|
}
|
||
|
}
|