31 lines
837 B
PHP
31 lines
837 B
PHP
|
<?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];
|
||
|
}
|
||
|
}
|