You are here

class HydratingIteratorIterator in Zircon Profile 8

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

Hierarchy

Expanded class hierarchy of HydratingIteratorIterator

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

File

vendor/zendframework/zend-hydrator/src/Iterator/HydratingIteratorIterator.php, line 17

Namespace

Zend\Hydrator\Iterator
View source
class HydratingIteratorIterator extends IteratorIterator implements HydratingIteratorInterface {

  /**
   * @var HydratorInterface
   */
  protected $hydrator;

  /**
   * @var object
   */
  protected $prototype;

  /**
   * @param HydratorInterface $hydrator
   * @param Iterator $data
   * @param string|object $prototype Object or class name to use for prototype.
   */
  public function __construct(HydratorInterface $hydrator, Iterator $data, $prototype) {
    $this
      ->setHydrator($hydrator);
    $this
      ->setPrototype($prototype);
    parent::__construct($data);
  }

  /**
   * @inheritdoc
   */
  public function setPrototype($prototype) {
    if (is_object($prototype)) {
      $this->prototype = $prototype;
      return;
    }
    if (!class_exists($prototype)) {
      throw new InvalidArgumentException(sprintf('Method %s was passed an invalid class name: %s', __METHOD__, $prototype));
    }
    $this->prototype = new $prototype();
  }

  /**
   * @inheritdoc
   */
  public function setHydrator(HydratorInterface $hydrator) {
    $this->hydrator = $hydrator;
  }

  /**
   * @return object Returns hydrated clone of $prototype
   */
  public function current() {
    $currentValue = parent::current();
    $object = clone $this->prototype;
    $this->hydrator
      ->hydrate($currentValue, $object);
    return $object;
  }

}

Members