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 single structures like:
*
* $data = [
* 'myObject' => [
* 4 => 5
* ]
* ];
* $structure = [
* 'type' => 'assoc-single',
* 'prefix' => 'my_object',
* 'use' => 'raw' // if raw, uses non mapped keys to fetch values
*/
class Single extends Type\Single
{
* {@inheritdoc}
public function run(&$data, $key = null)
$new = [];
foreach ($data as $key => $value) {
if (!is_array($value)) { // check for single to be sure!
$oldKey = $key;
parent::run($key);
if ($value) {
if ($this->options['use'] == 'raw') {
parent::run($value, $oldKey . '_' . $value);
} else {
parent::run($value, $key . '_' . $value);
}
unset($data[$oldKey]);
$new[$key] = $value;
$data += $new; // yep, union operator here!