Completed
Push — master ( 709dbb...f12a68 )
by Tobias
09:11
created

FakeRequestListener::onKernelRequest()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the BazingaGeocoderBundle package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @license    MIT License
9
 */
10
11
namespace Bazinga\GeocoderBundle\EventListener;
12
13
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
14
use Symfony\Component\HttpKernel\HttpKernelInterface;
15
16
/**
17
 * @author William Durand <[email protected]>
18
 */
19
class FakeRequestListener
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $fakeIp = null;
25
26
    public function __construct($fakeIp)
27
    {
28
        $this->fakeIp = $fakeIp;
29
    }
30
31
    public function onKernelRequest(GetResponseEvent $event)
32
    {
33
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
34
            return;
35
        }
36
37
        if (null !== $this->fakeIp && !empty($this->fakeIp)) {
38
            $event->getRequest()->server->set('REMOTE_ADDR', $this->fakeIp);
39
        }
40
    }
41
42
    public function getFakeIp()
43
    {
44
        return $this->fakeIp;
45
    }
46
}
47