Version 3.0
New technologies
This commit is contained in:
26
api/common/Alias/Factory/Model.php
Normal file
26
api/common/Alias/Factory/Model.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user