/** * Return the identifying key of the current element. * Similar to the key() function for arrays in PHP * * @return mixed either an integer or a string */ public function key() { if ($this->Handle) { return $this->Handle->key(); } return null; }
/** * Method for SeekableIterator interface. Takes a posiiton and traverses the file to that position * The value can be retrieved with a `current()` call afterwards. * * @param int Position in file */ public function seek($Position) { if (!$this->Handle) { throw new OutOfBoundsException('SpreadsheetReader: No file opened'); } $CurrentIndex = $this->Handle->key(); if ($CurrentIndex != $Position) { if ($Position < $CurrentIndex || is_null($CurrentIndex) || $Position == 0) { $this->rewind(); } while ($this->Handle->valid() && $Position > $this->Handle->key()) { $this->Handle->next(); } if (!$this->Handle->valid()) { throw new OutOfBoundsException('SpreadsheetError: Position ' . $Position . ' not found'); } } return null; }
/** * @param int $position * * @return null * @throws OutOfBoundsException */ public function seek($position) { if (!$this->Handle) { return null; } if ($position != $this->Handle->key()) { if (0 == $position) { $this->rewind(); return; } elseif ($position > 0) { if ($this->Handle->key() === null || $position < $this->Handle->key()) { $this->rewind(); } while ($nodeStr = $this->Handle->next()) { if ($this->Handle->key() == $position) { return; } } } throw new OutOfBoundsException(Mage::helper('importexport')->__('Invalid seek position')); } return null; }