当前位置: 首页>>代码示例>>PHP>>正文


PHP iterator_apply函数代码示例

本文整理汇总了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.';
}
开发者ID:NicoTn,项目名称:createFileStruct,代码行数:7,代码来源:createFileStruct.php

示例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));
 }
开发者ID:hausdesign,项目名称:zf-library,代码行数:7,代码来源:Reflection.php

示例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);
 }
开发者ID:Zumochi,项目名称:pathfinder,代码行数:61,代码来源:ccpsystemsmapper.php

示例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();
 }
开发者ID:adrianoaguiar,项目名称:magento-elasticsearch-module,代码行数:18,代码来源:Index.php

示例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;
 }
开发者ID:nextframework,项目名称:next,代码行数:20,代码来源:RowSet.php

示例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();
    }
}
开发者ID:ray0916,项目名称:learn,代码行数:11,代码来源:base.php

示例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);
 }
开发者ID:shounakgupte,项目名称:robots.txt,代码行数:18,代码来源:Rules.php

示例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;
 }
开发者ID:nextframework,项目名称:next,代码行数:26,代码来源:Applications.php

示例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));
开发者ID:ralf000,项目名称:PHP4,代码行数:10,代码来源:18-iteratorApply.php

示例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;
 }
开发者ID:Alpha-Hydro,项目名称:alpha-hydro-antares,代码行数:29,代码来源:CsvCatalogGeneratorController.php

示例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);
 }
开发者ID:intel352,项目名称:collections,代码行数:26,代码来源:Collection.php

示例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;
 }
开发者ID:nabeelio,项目名称:codon-superobject,代码行数:35,代码来源:SuperObject.php

示例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, ";"));
 }
开发者ID:nextframework,项目名称:next,代码行数:36,代码来源:Cookies.php

示例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;
    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:46,代码来源:PluginClassLoader.php

示例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;
    }
开发者ID:noose,项目名称:zf2,代码行数:24,代码来源:SimpleRouteStack.php


注:本文中的iterator_apply函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。