| @@ 17-59 (lines=43) @@ | ||
| 14 | /** |
|
| 15 | * Class ArrayWalkRecursiveTransformer |
|
| 16 | */ |
|
| 17 | class ArrayWalkRecursiveTransformer extends TransformerAbstract |
|
| 18 | { |
|
| 19 | /** |
|
| 20 | * Any callable with two argument which returns something |
|
| 21 | * |
|
| 22 | * @var callable |
|
| 23 | */ |
|
| 24 | protected $callable; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @var mixed |
|
| 28 | */ |
|
| 29 | protected $userdata; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @param callable $callable Worth nothing to say that the first callback argument should |
|
| 33 | * be a reference if you want anything to append to the record |
|
| 34 | * @param null|mixed $userdata |
|
| 35 | */ |
|
| 36 | public function __construct(callable $callable, $userdata = null) |
|
| 37 | { |
|
| 38 | $this->callable = $callable; |
|
| 39 | $this->userdata = $userdata; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * Execute the array_map call |
|
| 44 | * |
|
| 45 | * @param mixed $record |
|
| 46 | * |
|
| 47 | * @return mixed |
|
| 48 | */ |
|
| 49 | public function exec($record) |
|
| 50 | { |
|
| 51 | if (!\array_walk_recursive($this->callable, $record, $this->userdata)) { |
|
| 52 | throw new YaEtlException('array_walk_recursive call failed', 1, null, [ |
|
| 53 | 'record' => $record, |
|
| 54 | ]); |
|
| 55 | } |
|
| 56 | ||
| 57 | return $record; |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||
| @@ 18-60 (lines=43) @@ | ||
| 15 | /** |
|
| 16 | * Class ArrayWalkTransformer |
|
| 17 | */ |
|
| 18 | class ArrayWalkTransformer extends TransformerAbstract |
|
| 19 | { |
|
| 20 | /** |
|
| 21 | * Any callable with two argument which returns something |
|
| 22 | * |
|
| 23 | * @var callable |
|
| 24 | */ |
|
| 25 | protected $callable; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @var mixed |
|
| 29 | */ |
|
| 30 | protected $userdata; |
|
| 31 | ||
| 32 | /** |
|
| 33 | * @param callable $callable Worth nothing to say that the first callback argument should |
|
| 34 | * be a reference if you want anything to append to the record |
|
| 35 | * @param null|mixed $userdata |
|
| 36 | */ |
|
| 37 | public function __construct(callable $callable, $userdata = null) |
|
| 38 | { |
|
| 39 | $this->callable = $callable; |
|
| 40 | $this->userdata = $userdata; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * Execute the array_map call |
|
| 45 | * |
|
| 46 | * @param mixed $record |
|
| 47 | * |
|
| 48 | * @return mixed |
|
| 49 | */ |
|
| 50 | public function exec($record) |
|
| 51 | { |
|
| 52 | if (!\array_walk($this->callable, $record, $this->userdata)) { |
|
| 53 | throw new YaEtlException('array_walk call failed', 1, null, [ |
|
| 54 | 'record' => $record, |
|
| 55 | ]); |
|
| 56 | } |
|
| 57 | ||
| 58 | return $record; |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||