for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace GFG\Mapper\Data;
class Manager
{
/**
* @var MapperInterface
*/
private $mapper;
* @var MapperFactory
private $factory;
* @param MapperInterface $mapper
* @param MapperFactory $factory
public function __construct(
MapperInterface $mapper,
MapperFactory $factory
) {
$this->mapper = $mapper;
$this->factory = $factory;
}
* Map a given data based on a given structure
*
* @param array $data Data to be mapped
* @param array $structure How to map
* @param string $basePrefix
* @return void will change $data by reference
public function map(array &$data, array $structure, $basePrefix = null)
foreach ($structure as $key => $value) {
if (!isset($data[$key])) {
continue;
$keyData = &$data[$key];
if (!isset($value['prefix'])) {
$this->map($keyData, $value);
} else {
foreach ((array) $value['type'] as $type) {
$use = isset($value['use']) ? $value['use'] : '';
$inner = isset($value['inner']) ? $value['inner'] : '';
$type = $this->factory->create(
$this,
$type,
$this->mapper,
[
'prefix' => $basePrefix . $value['prefix'],
'use' => $use,
'inner' => $inner
]
);
$type->run($keyData);