3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Stdlib\Hydrator\Strategy
;
13 use Zend\Stdlib\ArrayUtils
;
15 final class StrategyChain
implements StrategyInterface
18 * Strategy chain for extraction
20 * @var StrategyInterface[]
22 private $extractionStrategies;
25 * Strategy chain for hydration
27 * @var StrategyInterface[]
29 private $hydrationStrategies;
34 * @param array|Traversable $extractionStrategies
36 public function __construct($extractionStrategies)
38 $extractionStrategies = ArrayUtils
::iteratorToArray($extractionStrategies);
39 $this->extractionStrategies
= array_map(
40 function (StrategyInterface
$strategy) {
41 // this callback is here only to ensure type-safety
47 $this->hydrationStrategies
= array_reverse($extractionStrategies);
53 public function extract($value)
55 foreach ($this->extractionStrategies
as $strategy) {
56 $value = $strategy->extract($value);
65 public function hydrate($value)
67 foreach ($this->hydrationStrategies
as $strategy) {
68 $value = $strategy->hydrate($value);