0.1.0
This commit is contained in:
30
common/Alias/Controller.php
Normal file
30
common/Alias/Controller.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace Incoviba\API\Common\Alias;
|
||||
|
||||
use Incoviba\API\Common\Define\Controller\Json;
|
||||
use Incoviba\API\Common\Factory\Mapper as MapperFactory;
|
||||
use Incoviba\Mapper\Mapper;
|
||||
|
||||
class Controller
|
||||
{
|
||||
use Json;
|
||||
|
||||
protected MapperFactory $mapperFactory;
|
||||
public function __construct(MapperFactory $mapperFactory) {
|
||||
$this->mapperFactory = $mapperFactory;
|
||||
}
|
||||
protected array $mappers;
|
||||
public function getMapper(string $name): Mapper
|
||||
{
|
||||
if (!class_exists($name)) {
|
||||
throw new \InvalidArgumentException("Mapper {$name} not found.");
|
||||
}
|
||||
if (!isset($this->mappers)) {
|
||||
$this->mappers = [];
|
||||
}
|
||||
if (!isset($this->mappers[$name])) {
|
||||
$this->mappers[$name] = $this->mapperFactory->get($name);
|
||||
}
|
||||
return $this->mappers[$name];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user