MiniAsset\Factory::assetCollection PHP Метод

assetCollection() публичный Метод

Create an AssetCollection with all the configured assets.
public assetCollection ( ) : AssetCollection
Результат AssetCollection
    public function assetCollection()
    {
        $assets = $this->config->targets();
        return new AssetCollection($assets, $this);
    }

Usage Example

Пример #1
0
 /**
  * Apply the asset middleware.
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request The request.
  * @param \Psr\Http\Message\ResponseInterface $response The response.
  * @param callable $next The callable to invoke the next middleware layer.
  * @return \Psr\Http\Message\ResponseInterface A response.
  */
 public function __invoke($request, $response, $next)
 {
     $path = $request->getUri()->getPath();
     if (strpos($path, $this->urlPrefix) !== 0) {
         // Not an asset request.
         return $next($request, $response);
     }
     $factory = new Factory($this->config);
     $assets = $factory->assetCollection();
     $targetName = substr($path, strlen($this->urlPrefix));
     if (!$assets->contains($targetName)) {
         // Unknown build.
         return $next($request, $response);
     }
     try {
         $build = $assets->get($targetName);
         $compiler = $factory->cachedCompiler($this->outputDir);
         $contents = $compiler->generate($build);
     } catch (Exception $e) {
         // Could not build the asset.
         $response->getBody()->write($e->getMessage());
         return $response->withStatus(400)->withHeader('Content-Type', 'text/plain');
     }
     return $this->respond($response, $contents, $build->ext());
 }
All Usage Examples Of MiniAsset\Factory::assetCollection