Skip to content

Commit 7051ba4

Browse files
author
Paul
committed
Rewrote Walk strategy as Delegate.
1 parent fa9d018 commit 7051ba4

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/Strategy/Walk.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
<?php
22
namespace ScriptFUSION\Mapper\Strategy;
33

4-
use ScriptFUSION\Mapper\MapperAware;
5-
use ScriptFUSION\Mapper\MapperAwareTrait;
64
use ScriptFUSION\Mapper\Mapping;
75

86
/**
97
* Walks a nested structure to the specified element in the same manner as Copy.
108
*/
11-
class Walk extends Copy implements MapperAware
9+
class Walk extends Delegate
1210
{
13-
use MapperAwareTrait;
14-
15-
private $expression;
11+
/**
12+
* @var Copy
13+
*/
14+
private $copy;
1615

1716
/**
1817
* @param Strategy|Mapping|array|mixed $expression Expression.
1918
* @param array|string $path Array of path components or string of `->`-delimited components.
2019
*/
2120
public function __construct($expression, $path)
2221
{
23-
parent::__construct($path);
22+
parent::__construct($expression);
2423

25-
$this->expression = $expression;
24+
$this->copy = new Copy($path);
2625
}
2726

2827
public function __invoke($data, $context = null)
2928
{
30-
return parent::__invoke($this->getMapper()->map($data, $this->expression, $context), $context);
29+
return call_user_func($this->copy, parent::__invoke($data, $context), $context);
3130
}
3231
}

0 commit comments

Comments
 (0)