Skip to content

Commit

Permalink
Rewrote Walk strategy as Delegate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul committed Feb 1, 2017
1 parent fa9d018 commit 7051ba4
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Strategy/Walk.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
<?php
namespace ScriptFUSION\Mapper\Strategy;

use ScriptFUSION\Mapper\MapperAware;
use ScriptFUSION\Mapper\MapperAwareTrait;
use ScriptFUSION\Mapper\Mapping;

/**
* Walks a nested structure to the specified element in the same manner as Copy.
*/
class Walk extends Copy implements MapperAware
class Walk extends Delegate
{
use MapperAwareTrait;

private $expression;
/**
* @var Copy
*/
private $copy;

/**
* @param Strategy|Mapping|array|mixed $expression Expression.
* @param array|string $path Array of path components or string of `->`-delimited components.
*/
public function __construct($expression, $path)
{
parent::__construct($path);
parent::__construct($expression);

$this->expression = $expression;
$this->copy = new Copy($path);
}

public function __invoke($data, $context = null)
{
return parent::__invoke($this->getMapper()->map($data, $this->expression, $context), $context);
return call_user_func($this->copy, parent::__invoke($data, $context), $context);
}
}

0 comments on commit 7051ba4

Please sign in to comment.