Example #1
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;
     }
 }
Example #2
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();
     }
 }
Example #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());
     }
 }
Example #4
0
 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";
 }
Example #5
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);
 }
 /**
  * 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);
 }
Example #7
0
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());
    }
}
 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);
 }
Example #9
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);
 }
Example #10
0
 public function getIterator()
 {
     $it = new AppendIterator();
     $it->append(new ArrayIterator(array($this->head())));
     if (is_string($this->_body)) {
         $it->append(new ArrayIterator(array($this->_body)));
     } elseif (is_array($this->_body)) {
         $it->append(new ArrayIterator($this->_body));
     } elseif ($this->_body instanceof Iterator) {
         $it->append($this->_body);
     }
     return $it;
 }
Example #11
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;
 }
Example #12
0
 /**
  * Adds an input path
  *
  * @param \r8\FileSys $input
  * @return \vc\App\Paths Returns a self reference
  */
 public function addInput(\r8\FileSys $input)
 {
     $input = clone $input;
     if ($input->isFile()) {
         $this->inputs->append(new \ArrayIterator(array($input)));
     } else {
         if ($input->isDir()) {
             $input->setIncludeDots(FALSE);
             $this->inputs->append(new \RecursiveIteratorIterator($input));
         } else {
             throw new \r8\Exception\Argument(0, 'Input', 'Path does not exist');
         }
     }
     return $this;
 }
Example #13
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;
 }
Example #14
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;
 }
Example #15
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";
 }
 /**
  * Add an iterator to the end of the list of iterators
  *
  * @param \Iterator $iterator
  */
 public function append(\Iterator $iterator)
 {
     if (!$iterator instanceof ArrayAccessIteratorInterface) {
         throw new \InvalidArgumentException('Iterator must implement the ArrayAccessIteratorInterface interface');
     }
     $this->iterators[] = $iterator;
     parent::append($iterator);
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     $iterator = new \AppendIterator();
     foreach ($this->currencies as $currencies) {
         $iterator->append($currencies->getIterator());
     }
     return $iterator;
 }
Example #18
0
 /**
  * @inheritDoc
  */
 public function collect() : \Iterator
 {
     $iterator = new \AppendIterator();
     foreach ($this->collectors as $collector) {
         $iterator->append($collector->collect());
     }
     return $iterator;
 }
 /**
  * @return void
  */
 protected function _setAppendIterator()
 {
     $this->_appendIterator = new AppendIterator();
     $this->_appendIterator->append(new PagesIterator());
     foreach ($this->_models as $a_model) {
         $this->_appendIterator->append($this->_getSitemapEntriesIterator($a_model));
     }
 }
Example #20
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;
 }
Example #22
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;
 }
 /**
  * {@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;
 }
Example #24
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);
     }
 }
 protected function _eachGetIterator($method, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL)
 {
     $it = new \AppendIterator();
     $arr = array();
     foreach ($this as $el) {
         $tmp = $el->{$method}($arg1, $arg2, $arg3);
         if ($tmp instanceof \Iterator) {
             $it->append($tmp);
         } else {
             $arr[] = $tmp;
         }
     }
     if (!empty($arr)) {
         $it->append(new \ArrayIterator($arr));
     }
     if ($it->valid()) {
         return new QuipXmlElementIterator($it);
     }
     return $this->{'no results'};
 }
 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;
 }
 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;
     }
 }
 public function attach(splFileInfo $fileInfo)
 {
     if ($fileInfo instanceof Iterator) {
         if ($fileInfo instanceof RecursiveDirectoryIterator) {
             $this->fileIterator->append(new RecursiveIteratorIterator($fileInfo));
         } else {
             $this->fileIterator->append($fileInfo);
         }
     } else {
         $this->nonTraversableItems->attach($fileInfo);
     }
 }
Example #29
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);
 }
Example #30
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;
 }