ControllerListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\EventListener;
4
5
use Doctrine\Common\Annotations\Reader;
6
use Loevgaard\DandomainAltapayBundle\Annotation\LogHttpTransaction;
7
use Loevgaard\DandomainAltapayBundle\Http\TransactionLogger;
8
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
9
10
class ControllerListener
11
{
12
    /**
13
     * @var TransactionLogger
14
     */
15
    private $transactionLogger;
16
17
    private $reader;
18
19
    public function __construct(TransactionLogger $transactionLogger, Reader $reader)
20
    {
21
        $this->transactionLogger = $transactionLogger;
22
        $this->reader = $reader;
23
    }
24
25
    public function onKernelController(FilterControllerEvent $event)
26
    {
27
        $controller = $event->getController();
28
29
        if (!$event->isMasterRequest() || !is_array($controller)) {
30
            return false;
31
        }
32
33
        list($class, $method) = $controller;
34
35
        $controllerReflection = new \ReflectionObject($class);
36
        $methodReflection = $controllerReflection->getMethod($method);
37
        $annotation = $this->reader->getMethodAnnotation($methodReflection, LogHttpTransaction::class);
38
39
        if ($annotation) {
40
            $request = $event->getRequest();
41
            $this->transactionLogger->setRequest($request);
42
        }
43
44
        return true;
45
    }
46
}
47