コード例 #1
0
 public function testNextFailsIfFileNotFound()
 {
     $iterator = new RecursivePathsIterator(new ArrayIterator(array($this->tempDir . '/css', $this->tempDir . '/foo')), '/app');
     $iterator->rewind();
     $this->assertSame($this->tempDir . '/css', $iterator->key());
     $this->assertSame('/app', $iterator->current());
     try {
         $iterator->next();
         $this->fail('Expected a RuntimeException');
     } catch (RuntimeException $e) {
     }
     $this->assertFalse($iterator->valid());
     $this->assertNull($iterator->current());
     $this->assertNull($iterator->key());
 }
コード例 #2
0
ファイル: PathMapping.php プロジェクト: niklongstone/manager
 /**
  * Loads the mapping.
  *
  * @param Package           $containingPackage The package that contains the
  *                                             mapping.
  * @param PackageCollection $packages          A list of packages that can
  *                                             be referenced using
  *                                             `@vendor/package:` prefixes
  *                                             in the path references.
  *
  * @throws AlreadyLoadedException If the mapping is already loaded.
  */
 public function load(Package $containingPackage, PackageCollection $packages)
 {
     if (null !== $this->state) {
         throw new AlreadyLoadedException('The mapping is already loaded.');
     }
     $filesystemPaths = array();
     $loadErrors = array();
     foreach ($this->pathReferences as $relativePath) {
         $loadError = null;
         try {
             $absolutePath = $this->makeAbsolute($relativePath, $containingPackage, $packages);
             $this->assertFileExists($absolutePath, $relativePath, $containingPackage);
             $filesystemPaths[] = $absolutePath;
         } catch (NoSuchPackageException $loadError) {
         } catch (FileNotFoundException $loadError) {
         }
         if ($loadError) {
             $loadErrors[] = $loadError;
         }
     }
     $iterator = new RecursivePathsIterator(new ArrayIterator($filesystemPaths), $this->repositoryPath);
     foreach ($iterator as $filesystemPath => $repositoryPath) {
         $directoryEntries = array();
         // If the filesystem path is a directory, list all entries of the
         // directory recursively
         if ($iterator->hasChildren()) {
             $directoryEntries = iterator_to_array(new RecursiveIteratorIterator($iterator->getChildren(), RecursiveIteratorIterator::SELF_FIRST));
             ksort($directoryEntries);
         }
         $this->pathMappings = array_merge($this->pathMappings, array($filesystemPath => $repositoryPath), $directoryEntries);
     }
     $this->repositoryPaths = array_unique($this->pathMappings);
     $this->filesystemPaths = $filesystemPaths;
     $this->loadErrors = $loadErrors;
     $this->containingPackage = $containingPackage;
     sort($this->repositoryPaths);
     $this->refreshState();
 }