Recursively gets files in path
@param string $pattern
@param byte $flags
@return array
547418
protected final static function rglob($pattern, $flags = 0) {
		$files = glob($pattern, $flags);
		foreach (glob(dirname($pattern) . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir)
			$files = array_merge(self::rglob($dir . DIRECTORY_SEPARATOR . basename($pattern), $flags), $files);
		return $files;
	}
665527
public function grep($values, $pattern, $flags = '')
    {
        if (!isset($values)) {
            return null;
        }
        
        if (is_string($flags)) {
            $flags = $flags === 'invert' ? PREG_GREP_INVERT : 0;
        }
        
        return preg_grep($pattern, $values, $flags);
    }
438431
function regexp($pattern, $flags = null) {
        $regexp['pattern'] = $pattern;
        if ($flags) $regexp['flags'] = $flags;
        $this->data['regexp'] = $regexp;
        return $this;
    }
1271776
public function readDirRecursive( $dir, $pattern ) {

		$sub_dirs = glob( $dir . '/*', \GLOB_ONLYDIR );
		$files = array();
		if ( ! empty( $sub_dirs ) ) {
			foreach ( $sub_dirs as $sub_dir ) {
				$files = array_merge( $files, $this->readDirRecursive( $sub_dir, $pattern ) );
			}
		}
		$files = array_merge( $files, glob( $dir . '/' . $pattern, \GLOB_NOCHECK ) );

		return $files;
	}
909404
private static function firstWildcardInPattern($pattern)
    {
        $wildcards = ['*', '?', '[', '\\'];
        $wildcardSearch = function ($carry, $item) use ($pattern) {
            $position = strpos($pattern, $item);

            if ($position === false) {
                return $carry === false ? $position : $carry;
            }

            return $carry === false ? $position : min($carry, $position);
        };

        return array_reduce($wildcards, $wildcardSearch, false);
    }
615614
protected function getFilesByPattern($pattern)
    {
        $iterator = Injector::inst()->create('GreenFinder')
            ->in($this->getPath())
            ->name($pattern);
        $files = [];

        foreach ($iterator as $file) {
            $files[] = $this->getRelativePath() . '/' . $file->getRelativePathname();
        }

        return $files;
    }
801972
public static function globAll(string $baseDir, array $patterns, int $flags = 0): array
    {
        $files = [];
        $inverse = [];

        foreach ($patterns as $pattern) {
            if (strpos($pattern, '!') === 0) {
                $pattern = substr($pattern, 1);

                $inverse[] = static::glob(
                    rtrim($baseDir, '\\/') . '/' . ltrim($pattern, '\\/'),
                    $flags
                );
            } else {
                $files[] = static::glob(
                    rtrim($baseDir, '\\/') . '/' . ltrim($pattern, '\\/'),
                    $flags
                );
            }
        }

        if ($files !== []) {
            $files = array_unique(array_merge(...$files));
        }

        if ($inverse !== []) {
            $inverse = array_unique(array_merge(...$inverse));
        }

        return array_diff($files, $inverse);
    }
803956
function getFiles(res, pattern, options) {
  var files = res.split(/\r?\n/).filter(Boolean);
  if (files.length === 1 && files[0] === pattern) {
    files = [];
  } else if (options.realpath === true || options.follow === true) {
    files = toAbsolute(files, options);
  }
  if (files.length === 0) {
    if (options.nullglob === true) {
      return [pattern];
    }
    if (options.failglob === true) {
      return new Error('no matches:' + pattern);
    }
  }

  return files.filter(function(filepath) {
    return filepath !== '.' && filepath !== '..';
  });
}
1134532
protected function filterPaths(array $paths, $pattern, array $extensions=[])
    {
        if (!$this->isFilterPattern($pattern) && !$extensions) {
            return $paths;
        }
        return array_filter($paths, function ($path) use ($pattern, $extensions) {
            return $this->filterPath($path, $pattern, $extensions);
        });
    }
223185
protected static function systemGlob($pattern, $flags)
    {
        if ($flags) {
            $flagMap = [
                self::GLOB_MARK     => GLOB_MARK,
                self::GLOB_NOSORT   => GLOB_NOSORT,
                self::GLOB_NOCHECK  => GLOB_NOCHECK,
                self::GLOB_NOESCAPE => GLOB_NOESCAPE,
                self::GLOB_BRACE    => defined('GLOB_BRACE') ? GLOB_BRACE : 0,
                self::GLOB_ONLYDIR  => GLOB_ONLYDIR,
                self::GLOB_ERR      => GLOB_ERR,
            ];

            $globFlags = 0;

            foreach ($flagMap as $internalFlag => $globFlag) {
                if ($flags & $internalFlag) {
                    $globFlags |= $globFlag;
                }
            }
        } else {
            $globFlags = 0;
        }

        ErrorHandler::start();
        $res = glob($pattern, $globFlags);
        $err = ErrorHandler::stop();
        if ($res === false) {
            throw new Exception\RuntimeException("glob('{$pattern}', {$globFlags}) failed", 0, $err);
        }
        return $res;
    }
454848
protected function findFilesAsArray(string $regex, string $path) {
		if(!is_dir($path))
			return null;
		
		$files = $this->findFilesAsSplFileInfo($regex, $path);
		$result = [];
		
		foreach ($files as $item) {
			
			if($item instanceof SplFileInfo)				
				$result[] = [
					'realPath' => $item->getRealPath(),
					'path' => $item->getPath(),
					'filename' => $item->getFilename(),
					"type" => $item->getType()
				];
			
		}
		
		return $result;
	}
314802
public function getFiles(string $path, bool $isRecursive = false) : array
    {
        if (!$this->isDirectory($path)) {
            return [];
        }

        $files = [];
        $iter = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
            RecursiveIteratorIterator::SELF_FIRST,
            RecursiveIteratorIterator::CATCH_GET_CHILD
        );

        if (!$isRecursive) {
            $iter->setMaxDepth(0);
        }

        foreach ($iter as $path => $item) {
            if ($item->isFile()) {
                $files[] = $path;
            }
        }

        return $files;
    }
1216014
public static function listFiles($code_dir, $pattern = '/\.php$/')
    {
        $flags = FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS;
        $dir_iter = new RecursiveDirectoryIterator($code_dir, $flags);
        $iter_iter = new RecursiveIteratorIterator($dir_iter);
        return new RegexIterator($iter_iter, $pattern);
    }
1074919
public static function grep(array $arr, string $pattern, int $flags = 0): array
    {
        return Strings::pcre('\preg_grep', [$pattern, $arr, $flags]);
    }
40747
public function getNextStrpos($patterns)
    {
        $next = -1;
        $match = null;
        foreach ($patterns as $p) {
            $index = strpos($this->src, $p, $this->index);
            if ($index === false) {
                continue;
            }
            if ($next === -1 || $index < $next) {
                $next = $index;
                $match = $p;
            }
        }
        return array($next, $match);
    }
1333580
public function globRecursive($pattern, $flags = 0)
    {
        $maxDepth = $this->maxDepth();
        $depthKey = strval($maxDepth);

        if (isset(static::$globCache[$pattern][$depthKey])) {
            return static::$globCache[$pattern][$depthKey];
        }

        $depth = 1;
        $files = glob($pattern, $flags);
        foreach (glob(dirname($pattern).'/*', (GLOB_ONLYDIR|GLOB_NOSORT)) as $dir) {
            $files = array_merge($files, $this->globRecursive($dir.'/'.basename($pattern), $flags));
            $depth++;
            if ($maxDepth > 0 && $depth >= $maxDepth) {
                break;
            }
        }

        static::$globCache[$pattern][$depthKey] = array_filter($files, 'is_file');

        return $files;
    }
802991
protected function getSegments($pattern)
	{
		$segments = array();
		$parts = \explode("/", ltrim($pattern, "/"));

		foreach ($parts as $segment)
		{
			if (\strpos($segment, ":") !== false)
			{
				$segments[] = $this->parseSegment($segment);
			}
		}

		return $segments;
	}