You are here

class CompositeNamingStrategy in Zircon Profile 8.0

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

Hierarchy

Expanded class hierarchy of CompositeNamingStrategy

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

File

vendor/zendframework/zend-hydrator/src/NamingStrategy/CompositeNamingStrategy.php, line 12

Namespace

Zend\Hydrator\NamingStrategy
View source
class CompositeNamingStrategy implements NamingStrategyInterface {

  /**
   * @var array
   */
  private $namingStrategies = [];

  /**
   * @var NamingStrategyInterface
   */
  private $defaultNamingStrategy;

  /**
   * @param NamingStrategyInterface[]    $strategies            indexed by the name they translate
   * @param NamingStrategyInterface|null $defaultNamingStrategy
   */
  public function __construct(array $strategies, NamingStrategyInterface $defaultNamingStrategy = null) {
    $this->namingStrategies = array_map(function (NamingStrategyInterface $strategy) {

      // this callback is here only to ensure type-safety
      return $strategy;
    }, $strategies);
    $this->defaultNamingStrategy = $defaultNamingStrategy ?: new IdentityNamingStrategy();
  }

  /**
   * {@inheritDoc}
   */
  public function extract($name) {
    $strategy = isset($this->namingStrategies[$name]) ? $this->namingStrategies[$name] : $this->defaultNamingStrategy;
    return $strategy
      ->extract($name);
  }

  /**
   * {@inheritDoc}
   */
  public function hydrate($name) {
    $strategy = isset($this->namingStrategies[$name]) ? $this->namingStrategies[$name] : $this->defaultNamingStrategy;
    return $strategy
      ->hydrate($name);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CompositeNamingStrategy::$defaultNamingStrategy private property
CompositeNamingStrategy::$namingStrategies private property
CompositeNamingStrategy::extract public function Converts the given name so that it can be hydrated by the hydrator. Overrides NamingStrategyInterface::extract
CompositeNamingStrategy::hydrate public function Converts the given name so that it can be extracted by the hydrator. Overrides NamingStrategyInterface::hydrate
CompositeNamingStrategy::__construct public function