You are here

class StrategyChain in Zircon Profile 8

Same name in this branch
  1. 8 vendor/zendframework/zend-hydrator/src/Strategy/StrategyChain.php \Zend\Hydrator\Strategy\StrategyChain
  2. 8 vendor/zendframework/zend-stdlib/src/Hydrator/Strategy/StrategyChain.php \Zend\Stdlib\Hydrator\Strategy\StrategyChain
Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-hydrator/src/Strategy/StrategyChain.php \Zend\Hydrator\Strategy\StrategyChain

Hierarchy

Expanded class hierarchy of StrategyChain

1 file declares its use of StrategyChain
StrategyChain.php in vendor/zendframework/zend-stdlib/src/Hydrator/Strategy/StrategyChain.php

File

vendor/zendframework/zend-hydrator/src/Strategy/StrategyChain.php, line 15

Namespace

Zend\Hydrator\Strategy
View source
class StrategyChain implements StrategyInterface {

  /**
   * Strategy chain for extraction
   *
   * @var StrategyInterface[]
   */
  private $extractionStrategies;

  /**
   * Strategy chain for hydration
   *
   * @var StrategyInterface[]
   */
  private $hydrationStrategies;

  /**
   * Constructor
   *
   * @param array|Traversable $extractionStrategies
   */
  public function __construct($extractionStrategies) {
    $extractionStrategies = ArrayUtils::iteratorToArray($extractionStrategies);
    $this->extractionStrategies = array_map(function (StrategyInterface $strategy) {

      // this callback is here only to ensure type-safety
      return $strategy;
    }, $extractionStrategies);
    $this->hydrationStrategies = array_reverse($extractionStrategies);
  }

  /**
   * {@inheritDoc}
   */
  public function extract($value) {
    foreach ($this->extractionStrategies as $strategy) {
      $value = $strategy
        ->extract($value);
    }
    return $value;
  }

  /**
   * {@inheritDoc}
   */
  public function hydrate($value) {
    foreach ($this->hydrationStrategies as $strategy) {
      $value = $strategy
        ->hydrate($value);
    }
    return $value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StrategyChain::$extractionStrategies private property Strategy chain for extraction
StrategyChain::$hydrationStrategies private property Strategy chain for hydration
StrategyChain::extract public function Converts the given value so that it can be extracted by the hydrator. Overrides StrategyInterface::extract
StrategyChain::hydrate public function Converts the given value so that it can be hydrated by the hydrator. Overrides StrategyInterface::hydrate
StrategyChain::__construct public function Constructor