本文整理汇总了PHP中AppendIterator类的典型用法代码示例。如果您正苦于以下问题:PHP AppendIterator类的具体用法?PHP AppendIterator怎么用?PHP AppendIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AppendIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: concat
/**
* 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();
}
}
示例2: expandCluster
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";
}
示例3: init_iterator
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());
}
}
示例4: getExpressionPartsPattern
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";
}
示例5: getIterator
/**
* 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;
}
示例6: getFileIterator
/**
*
* @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;
}
示例7: iterator
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;
}
}
示例8: union
/**
* @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);
}
示例9: getIterator
/**
* {@inheritdoc}
*/
public function getIterator()
{
$iterator = new \AppendIterator();
foreach ($this->currencies as $currencies) {
$iterator->append($currencies->getIterator());
}
return $iterator;
}
示例10: collect
/**
* @inheritDoc
*/
public function collect() : \Iterator
{
$iterator = new \AppendIterator();
foreach ($this->collectors as $collector) {
$iterator->append($collector->collect());
}
return $iterator;
}
示例11: testIteratorCombining
/**
* 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);
}
示例12: build
/**
* @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;
}
示例13: split
/**
* 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;
}
示例14: getDirectoryIterator
/**
* 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;
}
示例15: test3
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());
}
}