records = $records; $this->entity = $entity; } /** * Récupère un éléments à l'index définit * @param int $index * @return mixed|null|string */ public function get(int $index) { if ($this->entity) { if (!isset($this->hydratedRecords[$index])) { $this->hydratedRecords[$index] = Hydrator::hydrate($this->records[$index], $this->entity); } return $this->hydratedRecords[$index]; } return $this->entity; } /** * Return the current element * @link http://php.net/manual/en/iterator.current.php * @return mixed Can return any type. * @since 5.0.0 */ public function current() { return $this->get($this->index); } /** * Move forward to next element * @link http://php.net/manual/en/iterator.next.php * @return void Any returned value is ignored. * @since 5.0.0 */ public function next(): void { $this->index++; } /** * Return the key of the current element * @link http://php.net/manual/en/iterator.key.php * @return mixed scalar on success, or null on failure. * @since 5.0.0 */ public function key() { return $this->index; } /** * Checks if current position is valid * @link http://php.net/manual/en/iterator.valid.php * @return boolean The return value will be casted to boolean and then evaluated. * Returns true on success or false on failure. * @since 5.0.0 */ public function valid() { return isset($this->records[$this->index]); } /** * Rewind the Iterator to the first element * @link http://php.net/manual/en/iterator.rewind.php * @return void Any returned value is ignored. * @since 5.0.0 */ public function rewind() { $this->index = 0; } /** * Whether a offset exists * @link http://php.net/manual/en/arrayaccess.offsetexists.php * @param mixed $offset

* An offset to check for. *

* @return boolean true on success or false on failure. *

*

* The return value will be casted to boolean if non-boolean was returned. * @since 5.0.0 */ public function offsetExists($offset) { return isset($this->records[$offset]); } /** * Offset to retrieve * @link http://php.net/manual/en/arrayaccess.offsetget.php * @param mixed $offset

* The offset to retrieve. *

* @return mixed Can return all value types. * @since 5.0.0 */ public function offsetGet($offset) { return $this->get($offset); } /** * Offset to set * @link http://php.net/manual/en/arrayaccess.offsetset.php * @param mixed $offset

* The offset to assign the value to. *

* @param mixed $value

* The value to set. *

* @return void * @throws \Exception * @since 5.0.0 */ public function offsetSet($offset, $value) { throw new \Exception("Can't alter records"); } /** * Offset to unset * @link http://php.net/manual/en/arrayaccess.offsetunset.php * @param mixed $offset

* The offset to unset. *

* @return void * @throws \Exception * @since 5.0.0 */ public function offsetUnset($offset) { throw new \Exception("Can't alter records"); } }