AssetManager\Resolver\PrioritizedPathsResolver::collect PHP Method

collect() public method

{@inheritDoc}
public collect ( )
    public function collect()
    {
        $collection = array();
        foreach ($this->getPaths() as $path) {
            $locations = new SplStack();
            $pathInfo = new SplFileInfo($path);
            $locations->push($pathInfo);
            $basePath = $this->normalizePath($pathInfo->getRealPath());
            while (!$locations->isEmpty()) {
                /** @var SplFileInfo $pathInfo */
                $pathInfo = $locations->pop();
                if (!$pathInfo->isReadable()) {
                    throw new Exception\RuntimeException(sprintf('%s is not readable.', $pathInfo->getPath()));
                }
                if ($pathInfo->isDir()) {
                    foreach (new DirectoryResource($pathInfo->getRealPath()) as $resource) {
                        $locations->push(new SplFileInfo($resource));
                    }
                } else {
                    $collection[] = substr($pathInfo->getRealPath(), strlen($basePath));
                }
            }
        }
        return array_unique($collection);
    }

Usage Example

 /**
  * Test Collect returns valid list of assets
  *
  * @covers \AssetManager\Resolver\PrioritizedPathsResolver::collect
  */
 public function testCollectDirectory()
 {
     $resolver = new PrioritizedPathsResolver();
     $resolver->addPath(realpath(__DIR__ . '/../'));
     $dir = substr(__DIR__, strrpos(__DIR__, '/', 0) + 1);
     $this->assertContains($dir . DIRECTORY_SEPARATOR . basename(__FILE__), $resolver->collect());
     $this->assertNotContains($dir . DIRECTORY_SEPARATOR . 'i-do-not-exist.php', $resolver->collect());
 }