[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/zendframework/zend-stdlib/src/Hydrator/Strategy/ -> StrategyChain.php (source)

   1  <?php
   2  /**
   3   * Zend Framework (http://framework.zend.com/)
   4   *
   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
   8   */
   9  
  10  namespace Zend\Stdlib\Hydrator\Strategy;
  11  
  12  use Traversable;
  13  use Zend\Stdlib\ArrayUtils;
  14  
  15  final class StrategyChain implements StrategyInterface
  16  {
  17      /**
  18       * Strategy chain for extraction
  19       *
  20       * @var StrategyInterface[]
  21       */
  22      private $extractionStrategies;
  23  
  24      /**
  25       * Strategy chain for hydration
  26       *
  27       * @var StrategyInterface[]
  28       */
  29      private $hydrationStrategies;
  30  
  31      /**
  32       * Constructor
  33       *
  34       * @param array|Traversable $extractionStrategies
  35       */
  36      public function __construct($extractionStrategies)
  37      {
  38          $extractionStrategies = ArrayUtils::iteratorToArray($extractionStrategies);
  39          $this->extractionStrategies = array_map(
  40              function (StrategyInterface $strategy) {
  41                  // this callback is here only to ensure type-safety
  42                  return $strategy;
  43              },
  44              $extractionStrategies
  45          );
  46  
  47          $this->hydrationStrategies = array_reverse($extractionStrategies);
  48      }
  49  
  50      /**
  51       * {@inheritDoc}
  52       */
  53      public function extract($value)
  54      {
  55          foreach ($this->extractionStrategies as $strategy) {
  56              $value = $strategy->extract($value);
  57          }
  58  
  59          return $value;
  60      }
  61  
  62      /**
  63       * {@inheritDoc}
  64       */
  65      public function hydrate($value)
  66      {
  67          foreach ($this->hydrationStrategies as $strategy) {
  68              $value = $strategy->hydrate($value);
  69          }
  70  
  71          return $value;
  72      }
  73  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1