setHydrator($hydrator); $this->setPrototype($prototype); parent::__construct($data); } /** * @inheritdoc * * @throws InvalidArgumentException if $prototype is a string, but refers to * a non-existent class. */ public function setPrototype($prototype) : void { 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) : void { $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; } }