本文整理汇总了PHP中iterator_apply函数的典型用法代码示例。如果您正苦于以下问题:PHP iterator_apply函数的具体用法?PHP iterator_apply怎么用?PHP iterator_apply使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iterator_apply函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFileStruct
function createFileStruct($arguments)
{
$cur_path = getcwd();
$iterator = new RecursiveArrayIterator($arguments);
iterator_apply($iterator, 'traverseStructure', array($iterator));
echo 'File structure complete.';
}
示例2: inspectDir
private function inspectDir($path)
{
$rdi = new RecursiveDirectoryIterator($path);
$rii = new RecursiveIteratorIterator($rdi);
$filtered = new HausDesign_Controller_Plugin_Reflection_Filter($rii);
iterator_apply($filtered, array($this, 'process'), array($filtered));
}
示例3: getData
/**
* get formatted data
* @return array
*/
public function getData()
{
// format functions
self::$map['effect'] = function ($iterator) {
$effect = $iterator['effect'];
switch ($iterator['effect']) {
case 'magnetar':
$effect = 'magnetar';
break;
case 'red giant':
$effect = 'redGiant';
break;
case 'pulsar':
$effect = 'pulsar';
break;
case 'wolf-rayet star':
$effect = 'wolfRayet';
break;
case 'cataclysmic variable':
$effect = 'cataclysmic';
break;
case 'black hole':
$effect = 'blackHole';
break;
}
return $effect;
};
// format functions
self::$map['security'] = function ($iterator) {
if ($iterator['security'] == 7 || $iterator['security'] == 8 || $iterator['security'] == 9) {
$trueSec = round($iterator['trueSec'], 3);
if ($trueSec <= 0) {
$security = '0.0';
} elseif ($trueSec < 0.5) {
$security = 'L';
} else {
$security = 'H';
}
} else {
$security = 'C' . $iterator['security'];
}
return $security;
};
// format functions
self::$map['type'] = function ($iterator) {
// TODO refactor
$type = 'w-space';
$typeId = 1;
if ($iterator['security'] == 7 || $iterator['security'] == 8 || $iterator['security'] == 9) {
$type = 'k-space';
$typeId = 2;
}
return ['id' => $typeId, 'name' => $type];
};
iterator_apply($this, 'self::recursiveIterator', [$this]);
return iterator_to_array($this, false);
}
示例4: _addAdvancedIndexData
/**
*
*
* @param array $index
* @param $storeId
* @param $productIds
* @return array
*/
protected function _addAdvancedIndexData(array $index, $storeId, $productIds)
{
$prefix = $this->_engine->getFieldsPrefix();
$prefixedCategoryData = $this->_getCatalogCategoryData($storeId, $productIds);
$prefixedPriceData = $this->_getCatalogProductPriceData($productIds);
$indexCollector = new ArrayObject();
$indexIterator = new ArrayIterator($index);
iterator_apply($indexIterator, array($this, '_advancedIndexCallback'), array($indexIterator, $indexCollector, $prefix, $prefixedCategoryData, $prefixedPriceData));
return $indexCollector->getArrayCopy();
}
示例5: setSource
/**
* Set Data Source from different sources
*
* @param ArrayIterator $source
* Source Data
*
* @return ArrayIterator
* Input ArrayIterator with its values modified to be instance of
* Next\DB\Table\Row
*/
protected function setSource($source)
{
parent::setSource($source);
$manager =& $this->manager;
iterator_apply($this->source, function (\Iterator $iterator) use($manager) {
$iterator->offsetSet($iterator->key(), new Row($manager, $iterator->current()));
return TRUE;
}, array($this->source));
return $this->source;
}
示例6: apply
function apply()
{
$arr = array('chen', 'wang', 'liu');
try {
$it = new ArrayIterator($arr);
iterator_apply($it, 'addCaps', array($it));
} catch (Exception $e) {
// echo the error message
echo $e->getMessage();
}
}
示例7: get
/**
* Retrieve rules for a given UA
* @param string $userAgent
* @return null|Rule
*/
public function get($userAgent)
{
$item = null;
$iterator = new \ArrayIterator($this->collection);
iterator_apply($iterator, function (\ArrayIterator $iterator, $userAgent) use(&$item) {
if ($iterator->key() != Rules::DEFAULT_UA && preg_match($iterator->key(), $userAgent) === 1) {
$item = $iterator->current();
return false;
}
return true;
}, [$iterator, $userAgent]);
return $item !== null ? $item : (isset($this->collection[self::DEFAULT_UA]) ? $this->collection[self::DEFAULT_UA] : null);
}
示例8: getAnnotations
/**
* Get Annotations Found
*
* @return array
* Found Annotations
*/
public function getAnnotations()
{
$data = new \ArrayIterator();
$domains = $this->matchDomainAnnotations($this->application);
if (count($domains) > 0) {
$data->offsetSet('Domains', $domains);
}
$data->offsetSet('Path', $this->matchPathAnnotation($this->application));
// Listing Controllers Methods and reducing (or amplifying) the list to its Action Methods
$actions = $this->application->getControllers()->getIterator();
iterator_apply($actions, function (\Iterator $iterator) {
$action = new Actions(new \ArrayIterator($iterator->current()->getClass()->getMethods()));
$iterator->offsetSet($iterator->key(), $action->getAnnotations());
return TRUE;
}, array($actions));
if ($actions->count() > 0) {
$data->offsetSet('Routes', $actions->getArrayCopy());
}
return $data;
}
示例9: someFunc
<?php
function someFunc($iterator)
{
print $iterator->current();
return true;
}
$array = array(1, 2, 3);
$iterator = new ArrayIterator($array);
iterator_apply($iterator, 'someFunc', array($iterator));
示例10: getArrayGroupProducts
/**
* @return array
* @throws Zend_Exception
*/
public function getArrayGroupProducts()
{
// $cache = Zend_Registry::get('cache');
//
// $cache->remove('fullCatalogProducts');
//Массив по группам
$arrayGroupProducts = array();
$categoryMapper = new Catalog_Model_Mapper_Categories();
$treeCategories = $categoryMapper->fetchTreeSubCategoriesInArray();
foreach ($treeCategories as $item) {
$this->setCategoryWithProducts(array());
$children = $item['subCategories'];
$it = new RecursiveArrayIterator($children);
iterator_apply($it, array('Utils_CsvCatalogGeneratorController', 'fetchCategoriesWithProducts'), array($it));
$categoryProducts = $this->getCategoryWithProducts();
if (!empty($categoryProducts)) {
foreach ($categoryProducts as $key => $categoryProduct) {
$products = $this->getProductsCategory($key);
$categoryProducts[$key]['products'] = $products;
}
}
$arrayGroupProducts[$item['id']] = $categoryProducts;
}
return $arrayGroupProducts;
}
示例11: partition
/**
* Partitions this collection in two collections according to a predicate.
* Keys are preserved in the resulting collections.
*
* @param Closure $p The predicate on which to partition.
*
* @return array An array with two elements. The first element contains the collection
* of elements where the predicate returned TRUE, the second element
* contains the collection of elements where the predicate returned FALSE.
*/
public function partition(Closure $p)
{
$trueColl = new static();
$falseColl = new static();
iterator_apply($this, function () use($p, $trueColl, $falseColl) {
$key = $this->key();
$current = $this->current();
if ($p($current, $key)) {
$trueColl->set($key, $current);
} else {
$falseColl->set($key, $current);
}
return true;
});
return array($trueColl, $falseColl);
}
示例12: findValue
/**
* Returns an iterator of the current position
* @param \RecursiveArrayIterator $node
* @param array $tree
* @return mixed|null
*/
protected function findValue(\RecursiveArrayIterator $node, $tree = [])
{
# Find the node we are looking for, and return the iterator and value
list($node, $node_value) = $this->findNode($node, $tree);
if ($node_value === null) {
return null;
}
# This node has no children, it's just a string value, replace and return
if ($node->hasChildren() === false) {
$node->offsetSet($node->key(), $this->parseTokens($node->current()));
return $node->current();
}
# The node we want has children, parse through the
# leafs and parse any tokens that are present in them
$rec_ii = new \RecursiveIteratorIterator($node->getChildren(), \RecursiveIteratorIterator::LEAVES_ONLY);
iterator_apply($rec_ii, function (\Iterator &$iter, &$node_value) {
$curr_key = $iter->key();
$curr_val = $this->parseTokens($iter->current());
$iter->offsetSet($curr_key, $curr_val);
# This is a bug in PHP or something - if $nodeValue is an array, then the
# offsetSet() doesn't "stick" the new values, since they're not passed
# into the iterator by reference. So this is a work-around
if (is_array($node_value) && isset($node_value[$curr_key])) {
$node_value[$curr_key] = $curr_val;
}
return true;
}, [&$rec_ii, &$node_value]);
return $node_value;
}
示例13: getCookies
/**
* Get registered Cookies
*
* @param boolean $asString
* If TRUE, instead a Collection, a string of all the cookies will be returned
*
* @return Next\Components\Iterator\Lists|Next\HTTP\Headers\Fields\Request\Cookie
*
* <p>
* If <strong>$asString</strong> is set to FALSE, the Cookies
* Lists Collection will be returned
* </p>
*
* <p>
* If <strong>$asString</strong> is TRUE, a well formed Request
* Cookie Header will be returned
* </p>
*/
public function getCookies($asString = FALSE)
{
if ($asString === FALSE) {
return $this->cookies->getCollection();
}
// Is there something to return?
if ($this->cookies->count() == 0) {
return NULL;
}
// Let's return as string
$cookieString = NULL;
$iterator = $this->cookies->getIterator();
iterator_apply($iterator, function (\Iterator $iterator) use(&$cookieString) {
$cookieString .= sprintf("%s;", $iterator->current()->getValue());
return TRUE;
}, array($iterator));
return new Cookie(rtrim($cookieString, ";"));
}
示例14: registerPlugins
/**
* Register many plugins at once
*
* If $map is a string, assumes that the map is the class name of a
* Traversable object (likely a ShortNameLocator); it will then instantiate
* this class and use it to register plugins.
*
* If $map is an array or Traversable object, it will iterate it to
* register plugin names/classes.
*
* For all other arguments, or if the string $map is not a class or not a
* Traversable class, an exception will be raised.
*
* @param string|array|Traversable $map
* @return PluginClassLoader
* @throws Exception\InvalidArgumentException
*/
public function registerPlugins($map)
{
if (is_string($map)) {
if (!class_exists($map)) {
throw new Exception\InvalidArgumentException('Map class provided is invalid');
}
$map = new $map;
}
if (is_array($map)) {
$map = new ArrayIterator($map);
}
if (!$map instanceof Traversable) {
throw new Exception\InvalidArgumentException('Map provided is invalid; must be traversable');
}
// iterator_apply doesn't work as expected with IteratorAggregate
if ($map instanceof IteratorAggregate) {
$map = $map->getIterator();
}
// iterator_apply is faster than foreach
$loader = $this;
iterator_apply($map, function() use ($loader, $map) {
$loader->registerPlugin($map->key(), $map->current());
return true;
});
return $this;
}
示例15: addRoutes
/**
* addRoutes(): defined by RouteStack interface.
*
* @see Route::addRoutes()
* @param mixed $routes
* @return RouteStack
*/
public function addRoutes($routes)
{
if (is_array($routes)) {
$routes = new ArrayIterator($routes);
} elseif (!$routes instanceof Traversable) {
throw new Exception\InvalidArgumentException('Routes provided are invalid; must be traversable');
}
$routeStack = $this;
iterator_apply($routes, function() use ($routeStack, $routes) {
$routeStack->addRoute($routes->key(), $routes->current());
return true;
});
return $this;
}