本文整理匯總了PHP中Iterator::getRawData方法的典型用法代碼示例。如果您正苦於以下問題:PHP Iterator::getRawData方法的具體用法?PHP Iterator::getRawData怎麽用?PHP Iterator::getRawData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Iterator
的用法示例。
在下文中一共展示了Iterator::getRawData方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: indexDatabase
/**
* Builds the index for the given collection
*
* @param DatabaseInterface|\Iterator $database
* @return $this
*/
public function indexDatabase($database)
{
// Clear the map
$this->map = array();
/** @var SplFixedArray $collection */
$collection = null;
if ($database instanceof DatabaseRawDataInterface) {
$collection = $database->getRawData();
}
if ($database instanceof SplFixedArray) {
// Use the fixed array as is
} elseif (is_array($database)) {
$collection = SplFixedArray::fromArray($database);
} elseif ($database instanceof \Iterator) {
$collection = SplFixedArray::fromArray(iterator_to_array($database));
} else {
throw new InvalidIndexException(sprintf('Can not build index of argument of type %s', is_object($database) ? get_class($database) : gettype($database)));
}
$position = 0;
$count = $collection->getSize();
if ($count > 0) {
do {
$tempEntry = DocumentUtility::assertDocumentIdentifier($database[$position]);
$this->addEntryWithPosition($tempEntry, $position);
} while (++$position < $count);
}
}
示例2: indexDatabase
/**
* Builds the index for the given collection
*
* @param DatabaseInterface|\Iterator $database
* @return $this
*/
public function indexDatabase($database)
{
// Clear the map
$this->map = array();
/** @var SplFixedArray $collection */
$collection = null;
if ($database instanceof DatabaseRawDataInterface) {
$collection = $database->getRawData();
} elseif ($database instanceof SplFixedArray) {
$collection = $database;
} elseif (is_array($database)) {
$collection = SplFixedArray::fromArray($database);
} elseif ($database instanceof \Iterator) {
$collection = SplFixedArray::fromArray(iterator_to_array($database));
} else {
throw new InvalidIndexException(sprintf('Can not build index of argument of type %s', is_object($database) ? get_class($database) : gettype($database)));
}
$position = 0;
$count = $collection->getSize();
$tempMap = array();
if ($count > 0) {
$collectionContainsDocumentObjects = $collection[0] instanceof DocumentInterface;
do {
$entry = $collection[$position];
if ($collectionContainsDocumentObjects) {
$key = DocumentUtility::assertDocumentIdentifier($entry)->getId();
} else {
$key = DocumentUtility::getIdentifierForDocument($entry);
}
// DebugUtility::var_dump('Index', $key);
if (isset($tempMap[$key])) {
throw new DuplicateEntryException(sprintf('Duplicate entry \'%s\' for identifier', $key), 1415046937);
}
$tempMap[$key] = $position;
} while (++$position < $count);
}
$this->map = $tempMap;
}