/** * Creates a new iterator. * * @param string $glob The glob pattern. * @param int $flags A bitwise combination of the flag constants in * {@link Glob}. */ public function __construct($glob, $flags = 0) { $basePath = Glob::getBasePath($glob, $flags); if (!Glob::isDynamic($glob) && file_exists($glob)) { // If the glob is a file path, return that path $innerIterator = new ArrayIterator(array($glob)); } elseif (is_dir($basePath)) { // Use the system's much more efficient glob() function where we can if (false === strpos($glob, '/**/') && false === strpos($glob, '://') && ('\\' !== DIRECTORY_SEPARATOR || false === strpos($glob, '[^'))) { $results = glob($glob, GLOB_BRACE); // $results may be empty or false if $glob is invalid if (empty($results)) { // Parse glob and provoke errors if invalid Glob::toRegEx($glob); // Otherwise return empty result set $innerIterator = new EmptyIterator(); } else { $innerIterator = new ArrayIterator($results); } } else { // Otherwise scan the glob's base directory for matches $innerIterator = new GlobFilterIterator($glob, new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basePath, RecursiveDirectoryIterator::CURRENT_AS_PATHNAME | RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST), GlobFilterIterator::FILTER_VALUE, $flags); } } else { // If the glob's base directory does not exist, return nothing $innerIterator = new EmptyIterator(); } parent::__construct($innerIterator); }
/** * Handles the "url" command. * * @param Args $args The console arguments. * @param IO $io The I/O. * * @return int The status code. */ public function handle(Args $args, IO $io) { foreach ($args->getArgument('path') as $path) { if (!Glob::isDynamic($path)) { $this->printUrl($path, $io); continue; } foreach ($this->repo->find($path) as $resource) { $this->printUrl($resource->getPath(), $io); } } return 0; }
/** * Creates the installation request. * * @param ResourceInstaller $installer The used resource installer. * @param InstallerDescriptor $installerDescriptor The descriptor of the * resource installer. * @param ResourceCollection $resources The resources to install. * @param AssetMapping $mapping The asset mapping. * @param Server $server The asset server. * @param string $rootDir The project's root directory. */ public function __construct(ResourceInstaller $installer, InstallerDescriptor $installerDescriptor, ResourceCollection $resources, AssetMapping $mapping, Server $server, $rootDir) { $glob = $mapping->getGlob(); $parameterValues = $server->getParameterValues(); $this->validateParameterValues($parameterValues, $installerDescriptor); $this->installer = $installer; $this->installerDescriptor = $installerDescriptor; $this->resources = $resources; $this->mapping = $mapping; $this->server = $server; $this->rootDir = $rootDir; $this->basePath = Glob::isDynamic($glob) ? Glob::getBasePath($glob) : $glob; $this->parameterValues = array_replace($installerDescriptor->getParameterValues(), $parameterValues); }
/** * Creates a new iterator. * * @param string $glob The glob pattern. * @param int $flags A bitwise combination of the flag constants in * {@link Glob}. */ public function __construct($glob, $flags = 0) { $basePath = Glob::getBasePath($glob); if (!Glob::isDynamic($glob) && file_exists($glob)) { // If the glob is a file path, return that path $innerIterator = new ArrayIterator(array($glob)); } elseif (is_dir($basePath)) { // Otherwise scan the glob's base directory for matches $innerIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basePath, RecursiveDirectoryIterator::CURRENT_AS_PATHNAME | RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST); } else { // If the glob's base directory does not exist, return nothing $innerIterator = new EmptyIterator(); } parent::__construct($glob, $innerIterator, self::FILTER_VALUE, $flags); }
/** * Constructor. * * @param FilesystemInterface $filesystem The filesystem to search * @param string $glob The glob pattern * @param int $flags A bitwise combination of the flag constants in {@see Glob} */ public function __construct(FilesystemInterface $filesystem, $glob, $flags = 0) { // Glob code requires absolute paths, so prefix path // with leading slash, but not before mount point if (strpos($glob, '://') > 0) { $glob = str_replace('://', ':///', $glob); } else { $glob = '/' . ltrim($glob, '/'); } if (!Glob::isDynamic($glob)) { // If the glob is a file path, return that path. $innerIterator = new \ArrayIterator([$glob => $filesystem->get($glob)]); } else { $basePath = Glob::getBasePath($glob); $innerIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filesystem, $basePath, RecursiveDirectoryIterator::KEY_FOR_GLOB), RecursiveIteratorIterator::SELF_FIRST); } parent::__construct($glob, $innerIterator, static::FILTER_KEY, $flags); }
/** * {@inheritdoc} */ public function contains($query, $language = 'glob') { $this->failUnlessGlob($language); $query = $this->sanitizePath($query); if (Glob::isDynamic($query)) { $iterator = $this->getGlobIterator($query); $iterator->rewind(); return $iterator->valid(); } return isset($this->resources[$query]); }
/** * {@inheritdoc} */ protected function getReferencesForGlob($glob, $flags = 0) { if (!Glob::isDynamic($glob)) { return $this->getReferencesForPath($glob); } return $this->getReferencesForRegex(Glob::getStaticPrefix($glob), Glob::toRegEx($glob), $flags); }