TurbolinksListener::onKernelResponse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Helthe Turbolinks package.
5
 *
6
 * (c) Carl Alexander <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Helthe\Component\Turbolinks\EventListener;
13
14
use Helthe\Component\Turbolinks\Turbolinks;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
use Symfony\Component\HttpKernel\Event\ResponseEvent;
17
use Symfony\Component\HttpKernel\HttpKernelInterface;
18
use Symfony\Component\HttpKernel\KernelEvents;
19
20
/**
21
 * Event listener that modifies the kernel response for the turbolinks javascript.
22
 *
23
 * @author Carl Alexander <[email protected]>
24
 */
25
class TurbolinksListener implements EventSubscriberInterface
26
{
27
    /**
28
     * @var Turbolinks
29
     */
30
    private $turbolinks;
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public static function getSubscribedEvents()
36
    {
37
        return array(
38
            KernelEvents::RESPONSE => ['onKernelResponse', -128],
39
        );
40
    }
41
42
    /**
43
     * Constructor.
44
     *
45
     * @param Turbolinks $turbolinks
46
     */
47
    public function __construct(Turbolinks $turbolinks)
48
    {
49
        $this->turbolinks = $turbolinks;
50
    }
51
52
    /**
53
     * Filters the Response.
54
     *
55
     * @param ResponseEvent $event
56
     */
57
    public function onKernelResponse(ResponseEvent $event)
58
    {
59
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
60
            return;
61
        }
62
63
        $this->turbolinks->decorateResponse($event->getRequest(), $event->getResponse());
64
    }
65
}
66