<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class LoginSubscriber implements EventSubscriberInterface
{
/**
* @param RequestEvent $event
*/
public function onKernelRequest(RequestEvent $event)
{
if ('login' === $event->getRequest()->attributes->get('_route')) {
$username = $event->getRequest()->request->get('_username');
$event->getRequest()->request->set('_username', trim($username));
$event->getRequest()->request->set('_password', trim($event->getRequest()->request->get('_password')));
return;
}
}
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => ['onKernelRequest', 9]
];
}
}