<?php
namespace Claromentis\Core\Twig;

$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"] ?: array()) + array("_4c05b95d6bb1191967ccfe5" . "8bffbbd86" => base64_decode("b25LZXJuZWxWaWV" . "3"), "_75ca9d2" . "1af5efc8" . "ea104438" . "8098af78" . "4" => base64_decode("dHdpZy5hcmd1bWVudHM" . "="), "_00b7858db26a1c1cadb1466f573d5d" . "80" => base64_decode("Y29tbW9uL2xheW91dHMvYmFzZV9" . "0d2lnX2h5YnJpZC5odG1s"), "_6d3a1bbb0c16fad009bf87b" . "15802998e" => base64_decode("dHdpZy50ZW" . "1wbGF0ZQ=="));
use Claromentis\Core\Event\EventSubscriberInterface;
use Claromentis\Core\Http\TemplaterCallResponse;
use Claromentis\Core\Http\TwigResponse;
use Claromentis\Core\Http\TwigTemplaterResponse;
use Claromentis\Core\Twig\Events\TwigPreRenderEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Twig;









class TwigRenderListener implements EventSubscriberInterface
{
    
    
    
    
    protected $twig;
    
    
    
    
    protected $dispatcher;
    
    
    
    
    
    
    
    public function __construct(Twig\Environment $_6b67522fca36b32553cd09de29b97ff8, EventDispatcherInterface $_b497ce6f2af10f67516aed0ecf34d8cf)
    {
        $this->twig = $_6b67522fca36b32553cd09de29b97ff8;
        $this->dispatcher = $_b497ce6f2af10f67516aed0ecf34d8cf;
    }
    public static function getSubscribedEvents()
    {
        return [KernelEvents::VIEW => [$GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_4c05b95d6bb119196" . "7ccfe58bffbbd86"], -4]];
    }
    
    
    
    
    
    
    
    
    
    
    
    public function onKernelView(GetResponseForControllerResultEvent $event)
    {
        $_fd5a3a643834299cbdadfc3540ba0bcb = $event->getControllerResult();
        
        
        if (!$_fd5a3a643834299cbdadfc3540ba0bcb instanceof TwigResponse) {
            return;
        }
        
        
        $this->dispatchPreRenderEvent($_fd5a3a643834299cbdadfc3540ba0bcb);
        
        
        $this->updateControllerResultEvent($event, $_fd5a3a643834299cbdadfc3540ba0bcb);
    }
    
    
    
    
    
    
    
    
    protected function dispatchPreRenderEvent(TwigResponse $_fd5a3a643834299cbdadfc3540ba0bcb)
    {
        $event = new TwigPreRenderEvent($_fd5a3a643834299cbdadfc3540ba0bcb->getTemplate(), $_fd5a3a643834299cbdadfc3540ba0bcb->getArguments());
        $this->dispatcher->dispatch(TwigEvents::PRE_RENDER, $event);
        $_fd5a3a643834299cbdadfc3540ba0bcb->setTemplate($event->getTemplate());
        $_fd5a3a643834299cbdadfc3540ba0bcb->setArguments($event->getArguments());
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    protected function updateControllerResultEvent(GetResponseForControllerResultEvent $event, TwigResponse $_fd5a3a643834299cbdadfc3540ba0bcb)
    {
        if ($_fd5a3a643834299cbdadfc3540ba0bcb instanceof TwigTemplaterResponse) {
            
            
            
            $_edae18fae8c53743e7224eb1325ebb6b = new TemplaterCallResponse($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_00b7858db26a1c1cadb14" . "66f573d5d80"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_6d3a1bbb0c16fad009bf87b158029" . "98e"] => $_fd5a3a643834299cbdadfc3540ba0bcb->getTemplate(), $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_75ca9d21af5efc8ea1044388098af" . "784"] => $_fd5a3a643834299cbdadfc3540ba0bcb->getArguments()], $_fd5a3a643834299cbdadfc3540ba0bcb->getPageTitle());
            $_edae18fae8c53743e7224eb1325ebb6b->http_status = $_fd5a3a643834299cbdadfc3540ba0bcb->getHttpStatus();
            $_edae18fae8c53743e7224eb1325ebb6b->http_headers = $_fd5a3a643834299cbdadfc3540ba0bcb->getHttpHeaders();
            $event->setControllerResult($_edae18fae8c53743e7224eb1325ebb6b);
        } else {
            
            
            $_fd5a3a643834299cbdadfc3540ba0bcb = new Response($this->twig->render($_fd5a3a643834299cbdadfc3540ba0bcb->getTemplate(), $_fd5a3a643834299cbdadfc3540ba0bcb->getArguments()), $_fd5a3a643834299cbdadfc3540ba0bcb->getHttpStatus(), $_fd5a3a643834299cbdadfc3540ba0bcb->getHttpHeaders());
            $event->setResponse($_fd5a3a643834299cbdadfc3540ba0bcb);
        }
    }
}