[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/zendframework/zend-stdlib/src/Hydrator/NamingStrategy/ -> CompositeNamingStrategy.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\NamingStrategy;
  11  
  12  final class CompositeNamingStrategy implements NamingStrategyInterface
  13  {
  14      /**
  15       * @var array
  16       */
  17      private $namingStrategies = array();
  18  
  19      /**
  20       * @var NamingStrategyInterface
  21       */
  22      private $defaultNamingStrategy;
  23  
  24      /**
  25       * @param NamingStrategyInterface[]    $strategies            indexed by the name they translate
  26       * @param NamingStrategyInterface|null $defaultNamingStrategy
  27       */
  28      public function __construct(array $strategies, NamingStrategyInterface $defaultNamingStrategy = null)
  29      {
  30          $this->namingStrategies = array_map(
  31              function (NamingStrategyInterface $strategy) {
  32                  // this callback is here only to ensure type-safety
  33                  return $strategy;
  34              },
  35              $strategies
  36          );
  37  
  38          $this->defaultNamingStrategy = $defaultNamingStrategy ?: new IdentityNamingStrategy();
  39      }
  40  
  41      /**
  42       * {@inheritDoc}
  43       */
  44      public function extract($name)
  45      {
  46          $strategy = isset($this->namingStrategies[$name])
  47              ? $this->namingStrategies[$name]
  48              : $this->defaultNamingStrategy;
  49  
  50          return $strategy->extract($name);
  51      }
  52  
  53      /**
  54       * {@inheritDoc}
  55       */
  56      public function hydrate($name)
  57      {
  58          $strategy = isset($this->namingStrategies[$name])
  59              ? $this->namingStrategies[$name]
  60              : $this->defaultNamingStrategy;
  61  
  62          return $strategy->hydrate($name);
  63      }
  64  }


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