public function onKernelResponse(FilterResponseEvent $event)
    {
        if ($event->isMasterRequest()
            || $event->getRequest()->attributes->get('_controller') !== $this->exceptionController) {
            return;
        }

        // Status code is not set by the exception controller but only by the
        // kernel at the very end.
        // So lets use the status code from the flatten exception instead.
        $statusCode = $event->getRequest()->attributes->get('exception')->getStatusCode();

        $dir = $this->getGifDir($statusCode);
        $gif = $this->getRandomGif($dir);
        $url = $this->getGifUrl($dir, $gif);

        $content = $event->getResponse()->getContent();

        if (version_compare(Kernel::VERSION, '3.2', '<')) {
            $content = preg_replace(
                '/<img alt="Exception detected!" src=".*" \/>/',
                sprintf('<img alt="Exception detected!" src="%s" data-gif style="width:145px" />', $url),
                $content
            );
        } elseif (version_compare(Kernel::VERSION, '3.3', '<')) {
            $content = preg_replace(
                '@<svg xmlns="http://www.w3.org/2000/svg" width="112"(.*?)</svg>@ims',
                sprintf('<img alt="Exception detected!" src="%s" data-gif style="width:145px" />', $url),
                $content
            );
        } else {
            $content = preg_replace(
                '@<div class="exception-illustration hidden-xs-down">(.*?)</div>@ims',
                sprintf('<div class="exception-illustration hidden-xs-down" style="opacity:1"><img alt="Exception detected!" src="%s" data-gif style="height:66px" /></div>', $url),
                $content
            );
        }

        $event->getResponse()->setContent($content);
    }
public function onKernelResponse(FilterResponseEvent $event)
    {
        if ($event->isMasterRequest()
            || $event->getRequest()->attributes->get('_controller') !== $this->exceptionController) {
            return;
        }

        // Status code is not set by the exception controller but only by the
        // kernel at the very end.
        // So lets use the status code from the flatten exception instead.
        $statusCode = $event->getRequest()->attributes->get('exception')->getStatusCode();

        $dir = $this->getGifDir($statusCode);
        $gif = $this->getRandomGif($dir);
        $url = $this->getGifUrl($dir, $gif);

        $content = $event->getResponse()->getContent();

        if (version_compare(Kernel::VERSION, '3.2', '<')) {
            $content = preg_replace(
                '/<img alt="Exception detected!" src=".*" \/>/',
                sprintf('<img alt="Exception detected!" src="%s" data-gif style="width:145px" />', $url),
                $content
            );
        } elseif (version_compare(Kernel::VERSION, '3.3', '<')) {
            $content = preg_replace(
                '@<svg xmlns="http://www.w3.org/2000/svg" width="112"(.*?)</svg>@ims',
                sprintf('<img alt="Exception detected!" src="%s" data-gif style="width:145px" />', $url),
                $content
            );
        } else {
            $content = preg_replace(
                '@<div class="exception-illustration hidden-xs-down">(.*?)</div>@ims',
                sprintf('<div class="exception-illustration hidden-xs-down" style="opacity:1"><img alt="Exception detected!" src="%s" data-gif style="height:66px" /></div>', $url),
                $content
            );
        }

        $event->getResponse()->setContent($content);
    }
public function onKernelResponse ( FilterResponseEvent $ event ) { if ( $ event -> isMasterRequest ( ) || $ event -> getRequest ( ) -> attributes -> get ( '_controller' ) !== $ this -> exceptionController ) { return ; } // Status code is not set by the exception controller but only by the // kernel at the very end. // So lets use the status code from the flatten exception instead. $ statusCode = $ event -> getRequest ( ) -> attributes -> get ( 'exception' ) -> getStatusCode ( ) ; $ dir = $ this -> getGifDir ( $ statusCode ) ; $ gif = $ this -> getRandomGif ( $ dir ) ; $ url = $ this -> getGifUrl ( $ dir , $ gif ) ; $ content = $ event -> getResponse ( ) -> getContent ( ) ; if ( version_compare ( Kernel :: VERSION , '3.2' , '<' ) ) { $ content = preg_replace ( '/<img alt="Exception detected!" src=".*" \/>/' , sprintf ( '<img alt="Exception detected!" src="%s" data-gif style="width:145px" />' , $ url ) , $ content ) ; } elseif ( version_compare ( Kernel :: VERSION , '3.3' , '<' ) ) { $ content = preg_replace ( '@<svg xmlns="http://www.w3.org/2000/svg" width="112"(.*?)</svg>@ims' , sprintf ( '<img alt="Exception detected!" src="%s" data-gif style="width:145px" />' , $ url ) , $ content ) ; } else { $ content = preg_replace ( '@<div class="exception-illustration hidden-xs-down">(.*?)</div>@ims' , sprintf ( '<div class="exception-illustration hidden-xs-down" style="opacity:1"><img alt="Exception detected!" src="%s" data-gif style="height:66px" /></div>' , $ url ) , $ content ) ; } $ event -> getResponse ( ) -> setContent ( $ content ) ; }
Handle the response for exception and replace the little Phantom by a random Gif.

@param FilterResponseEvent $event
Handle the response for exception and replace the little Phantom by a random Gif .