本文整理匯總了PHP中Zend\Cache\Storage\StorageInterface::getIterator方法的典型用法代碼示例。如果您正苦於以下問題:PHP StorageInterface::getIterator方法的具體用法?PHP StorageInterface::getIterator怎麽用?PHP StorageInterface::getIterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Cache\Storage\StorageInterface
的用法示例。
在下文中一共展示了StorageInterface::getIterator方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getPageItemCache
/**
* Returns the page item cache.
*
* @return array
*/
public function getPageItemCache()
{
$data = array();
if ($this->cacheEnabled()) {
$prefixLength = strlen(self::CACHE_TAG_PREFIX);
$cacheIterator = static::$cache->getIterator();
$cacheIterator->setMode(CacheIterator::CURRENT_AS_VALUE);
foreach ($cacheIterator as $key => $value) {
if (substr($key, 0, $prefixLength) == self::CACHE_TAG_PREFIX) {
$data[(int) substr($key, $prefixLength)] = $value;
}
}
}
return $data;
}
示例2: testIterator
public function testIterator()
{
if (!$this->_storage instanceof IterableInterface) {
$this->markTestSkipped("Storage doesn't implement IterableInterface");
}
$items = array('key1' => 'value1', 'key2' => 'value2');
$this->assertSame(array(), $this->_storage->setItems($items));
// check iterator aggregate
$iterator = $this->_storage->getIterator();
$this->assertInstanceOf('Zend\\Cache\\Storage\\IteratorInterface', $iterator);
$this->assertSame(IteratorInterface::CURRENT_AS_KEY, $iterator->getMode());
// check mode CURRENT_AS_KEY
$iterator = $this->_storage->getIterator();
$iterator->setMode(IteratorInterface::CURRENT_AS_KEY);
$keys = iterator_to_array($iterator, false);
sort($keys);
$this->assertSame(array_keys($items), $keys);
// check mode CURRENT_AS_VALUE
$iterator = $this->_storage->getIterator();
$iterator->setMode(IteratorInterface::CURRENT_AS_VALUE);
$result = iterator_to_array($iterator, true);
ksort($result);
$this->assertSame($items, $result);
}