本文整理汇总了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;
}