<?php
namespace LaunchPad\Bundle\LaunchPadBundle\Base\EventListener;
use Doctrine\ORM\EntityManagerInterface;
use LaunchPad\Bundle\LaunchPadBundle\Api\Controller\BaseApiController;
use LaunchPad\Bundle\LaunchPadBundle\Base\Service\User\UserActionService;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
class AppResponseListener
{
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @var UserActionService
*/
private $userActionService;
/**
* @var ContainerInterface
*/
private $container;
/** @var AuthorizationCheckerInterface */
private $authChecker;
/**
* AppResponseListener constructor.
*
* @param ContainerInterface $container
* @param AuthorizationCheckerInterface $authChecker
* @param UserActionService $userActionService
*/
public function __construct(
ContainerInterface $container,
UserActionService $userActionService,
EntityManagerInterface $em,
AuthorizationCheckerInterface $authChecker
)
{
$this->container = $container;
$this->userActionService = $userActionService;
$this->em = $em;
$this->authChecker = $authChecker;
}
/**
* Check if status success and set successful status in userAction
*
* @param ResponseEvent $event
*/
public function onKernelResponse(ResponseEvent $event)
{
$controller = $event->getRequest()->attributes->get('_controller');
$controller = explode('\\', $controller);
$controller = end($controller);
$controller = explode('::', $controller);
$controllerName = $controller[0];
$controllerName = substr($controllerName, 0, -10);
// Get controller action
$controllerAction = @$controller[1];
if (substr($controllerAction, -6) === 'Action') {
$controllerAction = substr($controllerAction, 0, -6);
}
$action = lcfirst($controllerName) . '.' . $controllerAction;
$userAction = $this->userActionService->getLastUserAction($action);
// if($action == 'twig.controller.show')
// dump($action);die;
// if ($action !== 'auth.login' || $action != 'twig.controller.show') {
//
// $userAction = $this->userActionService->getLastUserAction($action);
//
// if ($event->getResponse()->getStatusCode() === 200) {
// $userAction->setIsSuccessful(true);
// } else {
// $userAction->setIsSuccessful(false);
// }
//
// $this->em->flush();
// }
}
}