public function beforeDispatch(Event $event)
    {
        deprecationWarning(
            'AssetCompressorFilter is deprecated. ' .
            'You should update to use AssetCompress\Middleware\AssetCompressMiddleware instead.'
        );
        $request = $event->data['request'];
        $response = $event->data['response'];
        $config = $this->_getConfig();
        $production = !Configure::read('debug');
        if ($production && !$config->general('alwaysEnableController')) {
            return null;
        }

        // Make sure the request looks like an asset.
        $targetName = $this->getName($config, $request->url);
        if (!$targetName) {
            return null;
        }

        if (isset($request->query['theme'])) {
            $config->theme($request->query['theme']);
        }
        $factory = new Factory($config);
        $assets = $factory->assetCollection();
        if (!$assets->contains($targetName)) {
            return null;
        }
        $build = $assets->get($targetName);

        try {
            $compiler = $factory->cachedCompiler();
            $contents = $compiler->generate($build);
        } catch (Exception $e) {
            throw new NotFoundException($e->getMessage());
        }

        $response->type($build->ext());
        $response->body($contents);
        $event->stopPropagation();

        return $response;
    }
public function beforeDispatch(Event $event)
    {
        deprecationWarning(
            'AssetCompressorFilter is deprecated. ' .
            'You should update to use AssetCompress\Middleware\AssetCompressMiddleware instead.'
        );
        $request = $event->data['request'];
        $response = $event->data['response'];
        $config = $this->_getConfig();
        $production = !Configure::read('debug');
        if ($production && !$config->general('alwaysEnableController')) {
            return null;
        }

        // Make sure the request looks like an asset.
        $targetName = $this->getName($config, $request->url);
        if (!$targetName) {
            return null;
        }

        if (isset($request->query['theme'])) {
            $config->theme($request->query['theme']);
        }
        $factory = new Factory($config);
        $assets = $factory->assetCollection();
        if (!$assets->contains($targetName)) {
            return null;
        }
        $build = $assets->get($targetName);

        try {
            $compiler = $factory->cachedCompiler();
            $contents = $compiler->generate($build);
        } catch (Exception $e) {
            throw new NotFoundException($e->getMessage());
        }

        $response->type($build->ext());
        $response->body($contents);
        $event->stopPropagation();

        return $response;
    }
public function beforeDispatch ( Event $ event ) { deprecationWarning ( 'AssetCompressorFilter is deprecated. ' . 'You should update to use AssetCompress\Middleware\AssetCompressMiddleware instead.' ) ; $ request = $ event -> data [ 'request' ] ; $ response = $ event -> data [ 'response' ] ; $ config = $ this -> _getConfig ( ) ; $ production = ! Configure :: read ( 'debug' ) ; if ( $ production && ! $ config -> general ( 'alwaysEnableController' ) ) { return null ; } // Make sure the request looks like an asset. $ targetName = $ this -> getName ( $ config , $ request -> url ) ; if ( ! $ targetName ) { return null ; } if ( isset ( $ request -> query [ 'theme' ] ) ) { $ config -> theme ( $ request -> query [ 'theme' ] ) ; } $ factory = new Factory ( $ config ) ; $ assets = $ factory -> assetCollection ( ) ; if ( ! $ assets -> contains ( $ targetName ) ) { return null ; } $ build = $ assets -> get ( $ targetName ) ; try { $ compiler = $ factory -> cachedCompiler ( ) ; $ contents = $ compiler -> generate ( $ build ) ; } catch ( Exception $ e ) { throw new NotFoundException ( $ e -> getMessage ( ) ) ; } $ response -> type ( $ build -> ext ( ) ) ; $ response -> body ( $ contents ) ; $ event -> stopPropagation ( ) ; return $ response ; }
Checks if request is for a compiled asset, otherwise skip any operation

@param Event $event containing the request and response object
@throws \Cake\Network\Exception\NotFoundException
@return \Cake\Network\Response|null Response if the client is requesting a recognized asset, null otherwise
Checks if request is for a compiled asset otherwise skip any operation