예제 #1
0
 /**
  * Recurse through a file hierarchy and process each directory and file.
  * Returns an array of SplFileInfo objects, one for each item where the 
  * callback returned true.
  * 
  * @param Closure $callback
  * @param DirectoryIterator $dir
  * @return SplFileInfo[]
  */
 protected function recurse(Closure $callback, DirectoryIterator $dir, $options)
 {
     $matches = array();
     if ($options['depth'] === 0) {
         return $matches;
     }
     $options['depth']--;
     foreach ($dir as $fileInfo) {
         if ($fileInfo->isDot() || $fileInfo->islink()) {
             continue;
         }
         if (!$this->checkPath($fileInfo)) {
             continue;
         }
         $relativePath = $this->adapter->relativePath($fileInfo);
         $matches[$relativePath] = $this->process($callback, $fileInfo);
         if ($fileInfo->isDir() && !in_array($fileInfo->getBasename(), $options['exclude'])) {
             $found = $this->recurse($callback, $fileInfo->getFileInfo('DirectoryIterator'), $options);
             $matches = array_merge($matches, $found);
         }
     }
     return array_filter($matches);
 }