<?php

namespace App\EventListener;


use App\Entity\EntUser;
use App\Utils\Tools;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;

class ControllerListener
{
    private $router;
    private $tokenStorage;
    private $em;

    /**
     * ControllerListener constructor.
     * @param RouterInterface $router
     * @param TokenStorage $tokenStorage
     * @param EntityManager $em
     */
    public function __construct(RouterInterface $router, TokenStorage $tokenStorage, EntityManager $em)
    {
        $this->router = $router;
        $this->tokenStorage = $tokenStorage;
        $this->em = $em;
    }

    /**
     * On kernel request
     * @param GetResponseEvent $event
     */
    public function onKernelRequest(GetResponseEvent $event)
    {
//        ini_set("memory_limit","1024M");
//
//        // NOTE: Increase execution time (be careful)
//        ini_set('max_execution_time', 180);

//        $user = $this->tokenStorage->getToken()->getUser();
//        $attributeParams = $event->getRequest()->attributes;
//        $requestParams = $event->getRequest()->request;
//        $route = $attributeParams->get('_route');

    }

    public function onKernelException(GetResponseForExceptionEvent $event)
    {

    }

    public function onKernelResponse(FilterResponseEvent $event)
    {
        // Compress all responsesF
        ob_start('ob_gzhandler');
    }

    public function onKernelTerminate(PostResponseEvent $event)
    {
        //sleep(60);
    }

}