Exemple #1
0
 /**
  * Concatenates one or more foreach-able object into an Iterator.
  * If no objects provided, returns an empty iterator.
  * \AppendIterators provided will be deep copied.
  * 		This means changes to \AppendIterator parameters will not be reflected
  * 		in the resulting \Iterator.
  * @return \Iterator
  */
 public static function concat()
 {
     $argCount = \func_num_args();
     if ($argCount === 0) {
         return new \EmptyIterator();
     } elseif ($argCount === 1) {
         return Iterators::ensureIsIterator(\func_get_args()[0]);
     } else {
         $retval = new \AppendIterator();
         //Workaround for AppendIterator bugs
         //https://bugs.php.net/bug.php?id=49104
         //https://bugs.php.net/bug.php?id=62212
         $retval->append(new \ArrayIterator([0]));
         unset($retval->getArrayIterator()[0]);
         $recursiveAttach = static function ($iter) use(&$recursiveAttach, $retval) {
             foreach ($iter as $concatedIter) {
                 if ($concatedIter instanceof \AppendIterator) {
                     $recursiveAttach($concatedIter->getArrayIterator());
                 } elseif ($concatedIter instanceof \EmptyIterator) {
                     //Do not add it.
                 } else {
                     $retval->append($concatedIter);
                 }
             }
             return $retval;
         };
         return (new \Yasca\Core\FunctionPipe())->wrap(\func_get_args())->pipe([Iterators::_class, 'ensureIsIterator'])->pipe([Iterators::_class, 'select'], [Iterators::_class, 'ensureIsIterator'])->pipe($recursiveAttach)->unwrap();
     }
 }
Exemple #2
0
 private function expandCluster(&$point_id, &$point, &$neighborhood)
 {
     // Add point to current cluster
     $this->toCluster($point);
     // Iterate all neighbors
     $iterator_array = $neighborhood;
     $iterator = new \AppendIterator();
     $iterator->append(new \ArrayIterator($iterator_array));
     foreach ($iterator as $neighbor_id => $neighbor) {
         // echo "  foreach in $neighbor ($neighbor_id)\n";
         // Neighbor not yet visited
         if (!$this->isVisited($neighbor_id)) {
             // Mark neighbor as visited
             $this->setVisited($neighbor_id);
             // Search the neighbor's neighborhood for new points
             $neighbor_neighborhood = $this->search->regionQuery($neighbor_id, $this->eps);
             // echo "  current neighbor $neighbor has this neighbor_neighborhood around:\n";
             // print_r($neighbor_neighborhood);
             if (count($neighbor_neighborhood) >= $this->minPoints) {
                 // Filter out the points already in the iterator
                 $filtered = array_diff_key($neighbor_neighborhood, $iterator_array);
                 // Add new points to the loop
                 $iterator_array = array_replace($iterator_array, $filtered);
                 $iterator->append(new \ArrayIterator($filtered));
                 // echo "  appended!!\n";
             }
         }
         // Add to cluster
         $this->toCluster($neighbor);
     }
     // echo "  END FOREACH\n";
 }
Exemple #3
0
 function init_iterator()
 {
     $tmp_core_dir = '';
     if (is_dir($this->target_app->app_dir . '/' . $this->path)) {
         $tmp_core_dir = $this->target_app->app_dir . '/' . $this->path;
     }
     if ($tmp_core_dir) {
         $cong_files = array();
         if (defined('EXTENDS_DIR') && is_dir(EXTENDS_DIR . '/' . $this->target_app->app_id . '/' . $this->path)) {
             $EXTENDS_DIR = new DirectoryIterator(EXTENDS_DIR . '/' . $this->target_app->app_id . '/' . $this->path);
             #从
             $EXTENDS_DIR = new NewCallbackFilterIterator($EXTENDS_DIR, function ($current) {
                 return !$current->isDot();
             });
             foreach ($EXTENDS_DIR as $v) {
                 $cong_files[] = $v->getFilename();
             }
         }
         $core_dir = new DirectoryIterator($tmp_core_dir);
         #主
         $core_dir = new NewCallbackFilterIterator($core_dir, function ($current, $key, $iterator, $params) {
             if (!$current->isDot() && !in_array($current->getFilename(), $params)) {
                 return $current;
             }
         }, $cong_files);
         $iterator = new AppendIterator();
         if ($EXTENDS_DIR) {
             $iterator->append($EXTENDS_DIR);
         }
         $iterator->append($core_dir);
         return $iterator;
     } else {
         return new ArrayIterator(array());
     }
 }
 private function getExpressionPartsPattern()
 {
     $signs = ' ';
     $patterns = ['\\$[a-zA-Z_]+[a-zA-Z_0-9]+' => 25, ':[a-zA-Z_\\-0-9]+' => 16, '"(?:\\\\.|[^"\\\\])*"' => 21, "'(?:\\\\.|[^'\\\\])*'" => 21, '(?<!\\w)\\d+(?:\\.\\d+)?' => 20];
     $iterator = new \AppendIterator();
     $iterator->append(new \CallbackFilterIterator(new \ArrayIterator(self::$operators), function ($operator) {
         return !ctype_alpha($operator);
     }));
     $iterator->append(new \ArrayIterator(self::$punctuation));
     foreach ($iterator as $symbol) {
         $length = strlen($symbol);
         if ($length === 1) {
             $signs .= $symbol;
         } else {
             if (strpos($symbol, ' ') !== false) {
                 $symbol = "(?<=^|\\W){$symbol}(?=[\\s()\\[\\]]|\$)";
             } else {
                 $symbol = preg_quote($symbol, '/');
             }
             $patterns[$symbol] = $length;
         }
     }
     arsort($patterns);
     $patterns = implode('|', array_keys($patterns));
     $signs = preg_quote($signs, '/');
     return "/({$patterns}|[{$signs}])/i";
 }
Exemple #5
0
 /**
  * Index the all the files in the directory and sub directories
  *
  * @param string|null $directory
  * @return RecursiveDirectoryIterator
  */
 protected function getIterator($directory = null)
 {
     $directories = $this->config['content_directories'];
     // some flags to filter . and .. and follow symlinks
     $flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS;
     if ($directory) {
         //Iterate only this directory
         return new \RecursiveDirectoryIterator($directory, $flags);
     }
     if ($directories) {
         $directoryIterators = [];
         foreach ($directories as $directory) {
             //Create an array of the paths
             $directoryIterators[] = new \RecursiveDirectoryIterator(each($directory)[1], $flags);
         }
         $iterator = new \AppendIterator();
         foreach ($directoryIterators as $directoryIterator) {
             //Append the directory iterator to the iterator
             $iterator->append(new \RecursiveIteratorIterator($directoryIterator));
         }
     } else {
         throw new Exception("Unable to read the content path, check the configuration file.");
     }
     if (iterator_count($iterator) == 0) {
         throw new Exception("The content directory is empty.");
     }
     return $iterator;
 }
Exemple #6
0
 /**
  *
  * @param array|string $paths        	
  * @param array|string $suffixes        	
  * @param array|string $prefixes        	
  * @param array $exclude        	
  * @return AppendIterator
  */
 public function getFileIterator($paths, $suffixes = '', $prefixes = '', array $exclude = array())
 {
     if (is_string($paths)) {
         $paths = array($paths);
     }
     $paths = $this->getPathsAfterResolvingWildcards($paths);
     $exclude = $this->getPathsAfterResolvingWildcards($exclude);
     if (is_string($prefixes)) {
         if ($prefixes != '') {
             $prefixes = array($prefixes);
         } else {
             $prefixes = array();
         }
     }
     if (is_string($suffixes)) {
         if ($suffixes != '') {
             $suffixes = array($suffixes);
         } else {
             $suffixes = array();
         }
     }
     $iterator = new AppendIterator();
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $iterator->append(new File_Iterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::FOLLOW_SYMLINKS)), $suffixes, $prefixes, $exclude, $path));
         }
     }
     return $iterator;
 }
Exemple #7
0
 public function iterator()
 {
     $aIterator = $this->arrMsgQueue ? new \org\jecat\framework\pattern\iterate\ArrayIterator($this->arrMsgQueue) : new \EmptyIterator();
     // for child container's children
     if ($this->arrChildren) {
         foreach ($this->arrChildren as $aChild) {
             if ($aChild instanceof IMessageQueue) {
                 $aQueue = $aChild;
             } else {
                 if ($aChild instanceof IMessageQueueHolder) {
                     $aQueue = $aChild->messageQueue(false);
                 } else {
                     Assert::wrong("未知的错误");
                 }
             }
             if ($aQueue) {
                 if (empty($aMergedIterator)) {
                     $aMergedIterator = new \AppendIterator();
                     $aMergedIterator->append($aIterator);
                 }
                 $aMergedIterator->append($aQueue->iterator());
             }
         }
     }
     // return merged iterators
     if (!empty($aMergedIterator)) {
         return $aMergedIterator;
     } else {
         return $aIterator;
     }
 }
Exemple #8
0
 /**
  * @param array|\Traversable $enumerable
  * @param callable           $equalityComparer
  *
  * @return \Cubiche\Core\Enumerable\EnumerableInterface
  */
 public function union($enumerable, callable $equalityComparer = null)
 {
     $iterator = new \AppendIterator();
     $iterator->append(Enumerable::from($this)->getIterator());
     $iterator->append(Enumerable::from($enumerable)->getIterator());
     return Enumerable::from($iterator)->distinct($equalityComparer);
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     $iterator = new \AppendIterator();
     foreach ($this->currencies as $currencies) {
         $iterator->append($currencies->getIterator());
     }
     return $iterator;
 }
Exemple #10
0
 /**
  * @inheritDoc
  */
 public function collect() : \Iterator
 {
     $iterator = new \AppendIterator();
     foreach ($this->collectors as $collector) {
         $iterator->append($collector->collect());
     }
     return $iterator;
 }
 /**
  * Iterator can be combine, chained, filter, there are many in the SPL
  * and sadly they are rarely used.
  */
 public function testIteratorCombining()
 {
     // a fancy way to add a joker to the deck :
     $joker = array('JK' => 'Joker');
     $newDeck = new \AppendIterator();
     $newDeck->append($this->deck);
     $newDeck->append(new \ArrayIterator($joker));
     $this->assertCount(33, $newDeck);
 }
Exemple #12
0
 /**
  * @inheritdoc
  */
 public function build(CreateGoalsTask $createTask, array $options = [])
 {
     $options = array_merge($this->defaultOptions, $options);
     $result = new \AppendIterator();
     foreach ($options as $builderAlias => $builderOptions) {
         $result->append($this->findBuilder($builderAlias)->build($createTask, $builderOptions));
     }
     return $result;
 }
 /**
  * Split arguments by date range
  *
  * @param array $arguments
  */
 public function split(array $arguments = array())
 {
     $splittedArguments = new AppendIterator();
     foreach ($this->_options['Period'] as $Date) {
         $_arguments = $arguments;
         $_arguments['--range'] = $Date->format(Configure::read('Task.dateFormat'));
         $splittedArguments->append($this->splitInner($_arguments));
     }
     return $splittedArguments;
 }
Exemple #14
0
 /**
  * Return iterator to walk through directories
  *
  * @return \AppendIterator
  */
 public function getDirectoryIterator()
 {
     $result = new \AppendIterator();
     foreach ($this->getDirs() as $dir) {
         if (\Includes\Utils\FileManager::isDir($dir)) {
             $result->append($this->getDirectorySPLIterator($dir));
         }
     }
     return $result;
 }
function test3($firstData, $secondData)
{
    $firstIterator = new ArrayIterator($firstData);
    $secondIterator = new ArrayIterator($secondData);
    $append = new AppendIterator();
    $append->append($firstIterator);
    $append->append($secondIterator);
    foreach ($append as $key => $value) {
        printf("F: %s, S: %s, A: %s=>%s (%s)\n", $firstIterator->key(), $secondIterator->key(), $key, $value, $append->getIteratorIndex());
    }
}
Exemple #16
0
 protected function execute(InputInterface $input)
 {
     $iterator = new \AppendIterator();
     $writer = $this->getWriter($input);
     foreach ($input->getArgument('files') as $i => $file) {
         $iterator->append($this->getReader($input, $i));
     }
     foreach ($iterator as $data) {
         $writer->write($data);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getIterator()
 {
     if (1 === count($this->dirs)) {
         return $this->searchInDir($this->dirs[0]);
     }
     $iterator = new \AppendIterator();
     foreach ($this->dirs as $dir) {
         $iterator->append($this->searchInDir($dir));
     }
     return $iterator;
 }
 public function packageIterator($sLanguage = null, $sCountry = null, $sLibName = null)
 {
     if (empty($this->arrFolders)) {
         return new \EmptyIterator();
     } else {
         $aIterator = new \AppendIterator();
         foreach ($this->arrFolders as $sFolderPath) {
             $aIterator->append(new PackageIterator($sFolderPath, $sLanguage, $sCountry, $sLibName));
         }
         return $aIterator;
     }
 }
 private function findTypes(array $paths)
 {
     $types = new \AppendIterator();
     foreach ($paths as $path) {
         $finder = Finder::create()->in($path['path']);
         $finder->name($path['match']);
         $iterator = new ClassExtractorIterator($finder);
         $iterator = new DoctrineTypeIterator($iterator, $path['suffix']);
         $types->append(new \IteratorIterator($iterator));
     }
     return $types;
 }
Exemple #20
0
 function items($cacheId)
 {
     $iter = new \AppendIterator();
     foreach ($this->backends as $backend) {
         $backendIter = $backend->items($cacheId);
         if (is_array($backendIter)) {
             $backendIter = new \ArrayIterator($backendIter);
         }
         $iter->append($backendIter);
     }
     return new \Cachet\Util\ReindexingIterator($iter);
 }
Exemple #21
0
 /**
  * Publish th plugin to the WordPress plugin repository
  * @param Event $event
  */
 public static function jumpstart(Event $event)
 {
     // get information
     $info = static::questionnaire($event);
     // update file headers
     $files = new \AppendIterator();
     $files->append(new RegexIterator(new RecursiveDirectoryIterator('.'), static::$filePattern, RegexIterator::GET_MATCH));
     $files->append(new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator('src')), static::$filePattern, RegexIterator::GET_MATCH));
     static::updateFiles($event, $files, $info);
     // create composer.json
     static::mergeConfig($event, $info);
 }
 private function assertSequence(\AppendIterator $it, $sequence)
 {
     $str = new TestStr();
     $i1 = new TestArrayIterator([1, 2, 3], $str);
     $i2 = new TestArrayIterator([4, 5, 6], $str);
     $it->append($i1);
     $it->append($i2);
     foreach ($it as $item) {
         $str->str .= $item;
     }
     $this->assertSame($sequence, $str->str);
 }
Exemple #23
0
 public function __construct($seq, $aSeq)
 {
     $iterator = null;
     $itAppend = new AppendIterator();
     if (!is_null($seq)) {
         $iterator = Sloth::iter($seq);
         $itAppend->append($iterator);
     }
     foreach ($aSeq as $mSeq) {
         $itAppend->append(Sloth::iter($mSeq));
     }
     $this->iterator = $itAppend;
 }
Exemple #24
0
 /**
  * @return Dimension[]
  */
 public function getDimensions()
 {
     $dimensions = new \AppendIterator();
     $set = $this->set;
     foreach ($this->set->getArcsFromConcept($this->concept) as $arc) {
         if ($arc->getArcRole() == "http://xbrl.org/int/dim/arcrole/hypercube-dimension" && $arc instanceof Definition\Arc) {
             $dimensions->append(new \ArrayIterator(array_map(function (NamespaceId $id) use($set) {
                 return new Dimension($set, $set->getConcept($id));
             }, $arc->getToConcepts())));
         }
     }
     return $dimensions;
 }
 /** Construct from path and filename
  *
  * @param $path the directory to search in
  *              If path contains ';' then this parameter is split and every
  *              part of it is used as separate directory.
  * @param $file the name of the files to search fro
  */
 function __construct($path, $file)
 {
     $this->file = $file;
     $list = split(PATH_SEPARATOR, $path);
     if (count($list) <= 1) {
         parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
     } else {
         $it = new AppendIterator();
         foreach ($list as $path) {
             $it->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)));
         }
         parent::__construct($it);
     }
 }
Exemple #26
0
 public function getIterator()
 {
     $iterator = new \AppendIterator();
     // english pack is always empty since in default rdfs
     if ($this->langCode != 'en-US') {
         foreach ($this->extension->getManifest()->getInstallModelFiles() as $rdfpath) {
             $modelId = FileModel::getModelIdFromXml($rdfpath);
             $candidate = $this->extension->getDir() . 'locales' . DIRECTORY_SEPARATOR . $this->langCode . DIRECTORY_SEPARATOR . basename($rdfpath) . '.po';
             if (file_exists($candidate)) {
                 $iterator->append($this->getTriplesFromFile($candidate, $modelId));
             }
         }
     }
     return $iterator;
 }
Exemple #27
0
 public function get($class, $key)
 {
     $return = new AppendIterator();
     if (!is_array($key)) {
         $key = array($key);
     }
     foreach ($key as $k) {
         if (self::$cache->offsetExists($class)) {
             if (self::$cache->offsetGet($class)->offsetExists($k)) {
                 $return->append(self::$cache->offsetGet($class)->offsetGet($k));
             }
         }
     }
     return $return;
 }
 public function next()
 {
     if ($this->valid()) {
         parent::next();
         ++$this->key;
     }
 }
Exemple #29
0
 /**
  * AJAX action: Check access rights for creation of a submailbox.
  *
  * Variables used:
  *   - all: (integer) If 1, return all mailboxes. Otherwise, return only
  *          INBOX, special mailboxes, and polled mailboxes.
  *
  * @return string  HTML to use for the folder tree.
  */
 public function smartmobileFolderTree()
 {
     $ftree = $GLOBALS['injector']->getInstance('IMP_Ftree');
     /* Poll all mailboxes on initial display. */
     $this->_base->queue->poll($ftree->poll->getPollList(), true);
     $iterator = new AppendIterator();
     /* Add special mailboxes explicitly. INBOX should appear first. */
     $special = new ArrayIterator();
     $special->append($ftree['INBOX']);
     foreach (IMP_Mailbox::getSpecialMailboxesSort() as $val) {
         if (isset($ftree[$val])) {
             $special->append($ftree[$val]);
         }
     }
     $iterator->append($special);
     /* Now add polled mailboxes. */
     $filter = new IMP_Ftree_IteratorFilter($ftree);
     $filter->add(array($filter::CONTAINERS, $filter::REMOTE, $filter::SPECIALMBOXES));
     if (!$this->vars->all) {
         $filter->add($filter::POLLED);
     }
     $filter->mboxes = array('INBOX');
     $iterator->append($filter);
     return $ftree->createTree($this->vars->all ? 'smobile_folders_all' : 'smobile_folders', array('iterator' => $iterator, 'render_type' => 'IMP_Tree_Jquerymobile'))->getTree(true);
 }
Exemple #30
0
 /**
  * Construct
  *
  * @param array $iterators
  */
 public function __construct(array $iterators)
 {
     parent::__construct();
     foreach ($iterators as $iterator) {
         $this->append($iterator);
     }
 }