for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace GFG\Mapper\Data\Type\Assoc;
use GFG\Mapper\Data\MapperInterface;
use GFG\Mapper\Data\Type;
/**
* For assoc option structures like:
*
* $data = [
* 'myObject' => [
* 4 => [5, 6, 7]
* ]
* ];
* $structure = [
* 'type' => 'assoc-option',
* 'prefix' => 'my_object',
* 'use' => 'raw' // if raw, uses non mapped keys to fetch values
*/
class Option extends Type\Option
{
* {@inheritdoc}
public function run(&$data, $key = null)
$new = [];
foreach ($data as $key => $value) {
if (is_array($value)) { // check for option to be sure!
$oldKey = $key;
$key = $this->get($key);
if ($this->options['use'] == 'raw') {
parent::run($value, $oldKey);
} else {
parent::run($value, $key);
}
unset($data[$oldKey]);
$new[$key] = $value;
$data += $new; // yep, union operator here!