16/10/2014 - SYMFONY
With the event listener below, we're going to see what actions cause master and sub requests throughout the system. I've listed some of them below but I guess this list can be extended more.
External requests that directly come from the user action.
$this->redirect()
and return new Symfony\Component\HttpFoundation\RedirectResponse()
actions.return new Symfony\Component\HttpFoundation\Response()
class or other classes/methods.Internal requests that does not come from the user action.
$this->forward()
helper method.forward()
method.{% render ... %}
in twig templates.return $this->render()
helper method.parameters:
listener.log.file: '%kernel.logs_dir%/listener.log'
# football/app/logs/listener.log
services:
application_backend.listener.user_controller:
class: Application\BackendBundle\EventListener\UserControllerListener
arguments:
- %listener.log.file%
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
namespace Application\BackendBundle\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
class UserControllerListener
{
private $logFile;
private $message = [
true => 'Master request',
false => 'Sub request'
];
public function __construct($logFile)
{
$this->logFile = $logFile;
}
public function onKernelRequest(GetResponseEvent $event)
{
$this->logRequest(
$this->message[$event->isMasterRequest()],
$event->getRequest()->getMethod()
);
}
private function logRequest($message, $method = null)
{
file_put_contents(
$this->logFile,
file_exists($this->logFile)
? file_get_contents($this->logFile) . "\n" . $method . ':' . $message
: $method . ':' . $message
);
}
}
GET:Master request
GET:Sub request
GET:Master request
POST:Master request
GET:Master request
GET:Sub request
GET:Sub request
GET:Master request
GET:Master request
GET:Sub request
GET:Master request