You are here

class AggregateHydrator in Zircon Profile 8.0

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

Aggregate hydrator that composes multiple hydrators via events

Hierarchy

Expanded class hierarchy of AggregateHydrator

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

File

vendor/zendframework/zend-hydrator/src/Aggregate/AggregateHydrator.php, line 20

Namespace

Zend\Hydrator\Aggregate
View source
class AggregateHydrator implements HydratorInterface, EventManagerAwareInterface {
  const DEFAULT_PRIORITY = 1;

  /**
   * @var EventManagerInterface|null
   */
  protected $eventManager;

  /**
   * Attaches the provided hydrator to the list of hydrators to be used while hydrating/extracting data
   *
   * @param HydratorInterface $hydrator
   * @param int $priority
   */
  public function add(HydratorInterface $hydrator, $priority = self::DEFAULT_PRIORITY) {
    $this
      ->getEventManager()
      ->attachAggregate(new HydratorListener($hydrator), $priority);
  }

  /**
   * {@inheritDoc}
   */
  public function extract($object) {
    $event = new ExtractEvent($this, $object);
    $this
      ->getEventManager()
      ->trigger($event);
    return $event
      ->getExtractedData();
  }

  /**
   * {@inheritDoc}
   */
  public function hydrate(array $data, $object) {
    $event = new HydrateEvent($this, $object, $data);
    $this
      ->getEventManager()
      ->trigger($event);
    return $event
      ->getHydratedObject();
  }

  /**
   * {@inheritDoc}
   */
  public function setEventManager(EventManagerInterface $eventManager) {
    $eventManager
      ->setIdentifiers([
      __CLASS__,
      get_class($this),
    ]);
    $this->eventManager = $eventManager;
  }

  /**
   * {@inheritDoc}
   */
  public function getEventManager() {
    if (null === $this->eventManager) {
      $this
        ->setEventManager(new EventManager());
    }
    return $this->eventManager;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AggregateHydrator::$eventManager protected property
AggregateHydrator::add public function Attaches the provided hydrator to the list of hydrators to be used while hydrating/extracting data
AggregateHydrator::DEFAULT_PRIORITY constant
AggregateHydrator::extract public function Extract values from an object Overrides ExtractionInterface::extract
AggregateHydrator::getEventManager public function
AggregateHydrator::hydrate public function Hydrate $object with the provided $data. Overrides HydrationInterface::hydrate
AggregateHydrator::setEventManager public function