MiniAsset\Factory::cachedCompiler PHP Method

cachedCompiler() public method

Create a Caching Compiler
public cachedCompiler ( string $outputDir = '', boolean $debug = false ) : CachedCompiler
$outputDir string The directory to output cached files to.
$debug boolean Whether or not to enable debugging mode for the compiler.
return MiniAsset\Output\CachedCompiler
    public function cachedCompiler($outputDir = '', $debug = false)
    {
        return new CachedCompiler($this->cacher($outputDir), $this->compiler($debug));
    }

Usage Example

 /**
  * 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::cachedCompiler