또한 보기: Glob
부터: 1.0
저자: Bernhard Schussek (bschussek@gmail.com)
상속: extends RegexFilterIterator
예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * 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);
 }