42 lines
1.0 KiB
PHP
42 lines
1.0 KiB
PHP
<?php
|
|
namespace Incoviba\Common\Implement\Repository;
|
|
|
|
use Incoviba\Common\Define;
|
|
use Incoviba\Common\Define\Repository\Mapper;
|
|
|
|
class MapperParser implements Define\Repository\MapperParser
|
|
{
|
|
public function __construct(?array $columns = null)
|
|
{
|
|
if ($columns !== null) {
|
|
foreach ($columns as $column) {
|
|
$this->register($column);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected array $maps;
|
|
|
|
public function register(string $column, ?Mapper $mapper = null): Define\Repository\MapperParser
|
|
{
|
|
if ($mapper !== null) {
|
|
$this->maps[$column] = $mapper;
|
|
return $this;
|
|
}
|
|
$this->maps[$column] = [];
|
|
return $this;
|
|
}
|
|
public function getColumns(): array
|
|
{
|
|
return array_keys($this->maps);
|
|
}
|
|
public function hasMapper(string $column): bool
|
|
{
|
|
return is_a($this->maps[$column], Define\Repository\Mapper::class);
|
|
}
|
|
public function getMapper(string $column): Mapper
|
|
{
|
|
return $this->maps[$column];
|
|
}
|
|
}
|