AssetManager\Resolver\PathStackResolver::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()) {
                    continue;
                }
                if ($pathInfo->isDir()) {
                    $dir = new DirectoryResource($pathInfo->getRealPath());
                    foreach ($dir as $resource) {
                        $locations->push(new SplFileInfo($resource));
                    }
                } elseif (!isset($collection[$pathInfo->getPath()])) {
                    $collection[] = substr($pathInfo->getRealPath(), strlen($basePath));
                }
            }
        }
        return $collection;
    }

Usage Example

コード例 #1
0
 /**
  * Test Collect returns valid list of assets
  *
  * @covers \AssetManager\Resolver\PathStackResolver::collect
  */
 public function testCollectDirectory()
 {
     $resolver = new PathStackResolver();
     $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());
 }