HydratingIteratorIterator.php in Zircon Profile 8
File
vendor/zendframework/zend-hydrator/src/Iterator/HydratingIteratorIterator.php
View source
<?php
namespace Zend\Hydrator\Iterator;
use Iterator;
use IteratorIterator;
use Zend\Hydrator\Exception\InvalidArgumentException;
use Zend\Hydrator\HydratorInterface;
class HydratingIteratorIterator extends IteratorIterator implements HydratingIteratorInterface {
protected $hydrator;
protected $prototype;
public function __construct(HydratorInterface $hydrator, Iterator $data, $prototype) {
$this
->setHydrator($hydrator);
$this
->setPrototype($prototype);
parent::__construct($data);
}
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();
}
public function setHydrator(HydratorInterface $hydrator) {
$this->hydrator = $hydrator;
}
public function current() {
$currentValue = parent::current();
$object = clone $this->prototype;
$this->hydrator
->hydrate($currentValue, $object);
return $object;
}
}