| @@ 17-50 (lines=34) @@ | ||
| 14 | /** |
|
| 15 | * Class ArrayReplaceRecursiveTransformer |
|
| 16 | */ |
|
| 17 | class ArrayReplaceRecursiveTransformer extends TransformerAbstract |
|
| 18 | { |
|
| 19 | /** |
|
| 20 | * @var array |
|
| 21 | */ |
|
| 22 | protected $default; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @var array |
|
| 26 | */ |
|
| 27 | protected $override; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @param array $default An array of the default field values to use, if any |
|
| 31 | * @param array $override An array of the field to always set to the same value, if any |
|
| 32 | */ |
|
| 33 | public function __construct(array $default, array $override = []) |
|
| 34 | { |
|
| 35 | $this->default = $default; |
|
| 36 | $this->override = $override; |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Set defaults and/or overrides recursively in the record |
|
| 41 | * |
|
| 42 | * @param mixed $record |
|
| 43 | * |
|
| 44 | * @return mixed |
|
| 45 | */ |
|
| 46 | public function exec($record) |
|
| 47 | { |
|
| 48 | return \array_replace_recursive($this->default, $record, $this->override); |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||
| @@ 17-50 (lines=34) @@ | ||
| 14 | /** |
|
| 15 | * Class ArrayReplaceTransformer |
|
| 16 | */ |
|
| 17 | class ArrayReplaceTransformer extends TransformerAbstract |
|
| 18 | { |
|
| 19 | /** |
|
| 20 | * @var array |
|
| 21 | */ |
|
| 22 | protected $default; |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @var array |
|
| 26 | */ |
|
| 27 | protected $override; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * @param array $default An array of the default field values to use, if any |
|
| 31 | * @param array $override An array of the field to always set to the same value, if any |
|
| 32 | */ |
|
| 33 | public function __construct(array $default, array $override = []) |
|
| 34 | { |
|
| 35 | $this->default = $default; |
|
| 36 | $this->override = $override; |
|
| 37 | } |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Set defaults and/or overrides in the record |
|
| 41 | * |
|
| 42 | * @param mixed $record |
|
| 43 | * |
|
| 44 | * @return mixed |
|
| 45 | */ |
|
| 46 | public function exec($record) |
|
| 47 | { |
|
| 48 | return \array_replace($this->default, $record, $this->override); |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||