Implemented repository mapper, and venta show
This commit is contained in:
41
app/common/Implement/Repository/MapperParser.php
Normal file
41
app/common/Implement/Repository/MapperParser.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?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];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user