本文整理匯總了PHP中Index::getParser方法的典型用法代碼示例。如果您正苦於以下問題:PHP Index::getParser方法的具體用法?PHP Index::getParser怎麽用?PHP Index::getParser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Index
的用法示例。
在下文中一共展示了Index::getParser方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getData
/**
* Returns the data
*
* @return String
*/
public function getData()
{
if (is_null($this->data)) {
$this->data = $this->index->getParser()->getData($this->getOffset());
}
return $this->data;
}
示例2: readKeys
/**
* Returns keys from a offset
*
* The read range will be increased until at least one key will be found
* or the end of file was reached.
*
* @param int $offset
* @param int $direction
* @return array
* @throws IOIndexException
*/
public function readKeys($offset, $direction, $hints = Parser::HINT_NONE)
{
// If reading backwards, shift the offset left
$shiftedOffset = $direction == self::DIRECTION_BACKWARD ? $offset - $this->getReadLength() : $offset;
//TODO shift to a blocksize chunk
// Don't shift too far
if ($shiftedOffset < 0) {
$shiftedOffset = 0;
}
// Read data
\fseek($this->index->getFile()->getFilePointer(), $shiftedOffset);
$data = \fread($this->index->getFile()->getFilePointer(), $this->getReadLength());
if ($data === false) {
if (\feof($this->index->getFile()->getFilePointer())) {
return array();
} else {
throw new IOIndexException("Could not read file");
}
}
// Parse the read data
$keys = $this->index->getParser()->parseKeys($data, $shiftedOffset, $hints);
// Read more data if no keys were found
if (empty($keys)) {
// Only increase if there exists more data
if ($direction == self::DIRECTION_BACKWARD && $shiftedOffset == 0) {
return array();
} elseif ($direction == self::DIRECTION_FORWARD && $shiftedOffset + $this->getReadLength() >= $this->index->getFile()->getFileSize()) {
return array();
}
$this->increaseReadLength();
return $this->readKeys($offset, $direction);
}
return $keys;
}