public function onKernelController(FilterControllerEvent $event)
    {
        if (!is_array($controller = $event->getController())) {
            return;
        }

        // Only for SubRequests
        $subRequest = $event->getRequest();
        if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

        // Check if Annotation is present
        if (!$configuration = $subRequest->attributes->get('_andres_montanez_fragment_cache', false)) {
            return;
        }

        // Calculate Request Key
        $key = $this->getKey($configuration, $subRequest, $this->masterRequest);

        if (!$this->enabled) {
            return;
        }

        // If content is cached, return it
        $content = $this->cache->get($key);
        if ($content !== false) {
            $fragment = '';
            if ($this->debug) {
                $fragment .= '<!-- HIT - Begin Fragment Cache for KEY: ' . $key . ' -->';
            }

            $fragment .= $content;

            if ($this->debug) {
                $fragment .= '<!-- End Fragment Cache for KEY: ' . $key . ' -->';
            }

            $response = new Response($fragment);
            $event->setController(function () use ($response) {
                return $response;
            });

        } else {
            $subRequest->attributes->set('_andres_montanez_fragment_cache_key', $key);
        }

        return;
    }
public function onKernelController(FilterControllerEvent $event)
    {
        if (!is_array($controller = $event->getController())) {
            return;
        }

        // Only for SubRequests
        $subRequest = $event->getRequest();
        if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

        // Check if Annotation is present
        if (!$configuration = $subRequest->attributes->get('_andres_montanez_fragment_cache', false)) {
            return;
        }

        // Calculate Request Key
        $key = $this->getKey($configuration, $subRequest, $this->masterRequest);

        if (!$this->enabled) {
            return;
        }

        // If content is cached, return it
        $content = $this->cache->get($key);
        if ($content !== false) {
            $fragment = '';
            if ($this->debug) {
                $fragment .= '<!-- HIT - Begin Fragment Cache for KEY: ' . $key . ' -->';
            }

            $fragment .= $content;

            if ($this->debug) {
                $fragment .= '<!-- End Fragment Cache for KEY: ' . $key . ' -->';
            }

            $response = new Response($fragment);
            $event->setController(function () use ($response) {
                return $response;
            });

        } else {
            $subRequest->attributes->set('_andres_montanez_fragment_cache_key', $key);
        }

        return;
    }
public function onKernelController ( FilterControllerEvent $ event ) { if ( ! is_array ( $ controller = $ event -> getController ( ) ) ) { return ; } // Only for SubRequests $ subRequest = $ event -> getRequest ( ) ; if ( $ event -> getRequestType ( ) == HttpKernelInterface :: MASTER_REQUEST ) { return ; } // Check if Annotation is present if ( ! $ configuration = $ subRequest -> attributes -> get ( '_andres_montanez_fragment_cache' , false ) ) { return ; } // Calculate Request Key $ key = $ this -> getKey ( $ configuration , $ subRequest , $ this -> masterRequest ) ; if ( ! $ this -> enabled ) { return ; } // If content is cached, return it $ content = $ this -> cache -> get ( $ key ) ; if ( $ content !== false ) { $ fragment = '' ; if ( $ this -> debug ) { $ fragment .= '<!-- HIT - Begin Fragment Cache for KEY: ' . $ key . ' -->' ; } $ fragment .= $ content ; if ( $ this -> debug ) { $ fragment .= '<!-- End Fragment Cache for KEY: ' . $ key . ' -->' ; } $ response = new Response ( $ fragment ) ; $ event -> setController ( function ( ) use ( $ response ) { return $ response ; } ) ; } else { $ subRequest -> attributes -> set ( '_andres_montanez_fragment_cache_key' , $ key ) ; } return ; }
Listener for the Controller call

@param \Symfony\Component\HttpKernel\Event\FilterControllerEvent $event
@return void
Listener for the Controller call