qbbr.io / blog

Tags: ,
Source: markdown

src/Acme/DemoBundle/EventListener/AcmeKernelListener.php:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

namespace Acme\DemoBundle\EventListener;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;

class AcmeKernelListener
{
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function onKernelRequest(GetResponseEvent $event)
    {
        $container = $this->container;
        $kernel    = $event->getKernel();
        $request   = $event->getRequest();
        // u code
    }

    public function onKernelResponse(FilterResponseEvent $event)
    {
        $container = $this->container;
        $kernel    = $event->getKernel();
        $response  = $event->getResponse();
        $request   = $event->getRequest();
        // u code
    }
}

app/config/config.yml:

1
2
3
4
5
6
7
services:
    listener.requestresponse:
        class: Acme\DemoBundle\EventListener\AcmeKernelListener
        arguments: [ @service_container ]
        tags:
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
            - { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }
comments powered by Disqus
On your computer does not found Web Browser!
Plz install it.
Firefox
Chromium
Google Chrome
Safari
Opera