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