DispatcherPlugin::afterExecuteRoute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author @fabfuel <[email protected]>
4
 * @created 14.11.14, 08:39 
5
 */
6
namespace Fabfuel\Prophiler\Plugin\Phalcon\Mvc;
7
8
use Fabfuel\Prophiler\Benchmark\BenchmarkInterface;
9
use Fabfuel\Prophiler\Plugin\PluginAbstract;
10
use Phalcon\Events\Event;
11
use Phalcon\Mvc\DispatcherInterface;
12
13
/**
14
 * Class DispatcherPlugin
15
 */
16
class DispatcherPlugin extends PluginAbstract
17
{
18
    /**
19
     * @var BenchmarkInterface
20
     */
21
    protected $benchmarkDispatch;
22
23
    /**
24
     * @var BenchmarkInterface
25
     */
26
    protected $benchmarkRoute;
27
28
    /**
29
     * Start dispatch loop benchmark
30
     *
31
     * @param Event $event
32
     */
33 1
    public function beforeDispatchLoop(Event $event)
34
    {
35 1
        $name = get_class($event->getSource()) . '::dispatchLoop';
36 1
        $this->benchmarkDispatch = $this->getProfiler()->start($name, [], 'Dispatcher');
37 1
    }
38
39
    /**
40
     * Stop dispatch loop benchmark
41
     */
42 1
    public function afterDispatchLoop()
43
    {
44 1
        $this->getProfiler()->stop($this->benchmarkDispatch);
45 1
    }
46
47
    /**
48
     * Start execute route benchmark
49
     *
50
     * @param Event $event
51
     * @param DispatcherInterface $dispatcher
52
     */
53 1
    public function beforeExecuteRoute(Event $event, DispatcherInterface $dispatcher)
54
    {
55 1
        $name = get_class($event->getSource()) . '::executeRoute';
56
        $metadata = [
57 1
            'executed' => sprintf('%s::%sAction', get_class($dispatcher->getActiveController()), $dispatcher->getActionName()),
58 1
            'controller' => $dispatcher->getControllerName(),
59 1
            'action' => $dispatcher->getActionName(),
60 1
            'params' => $dispatcher->getParams(),
61 1
        ];
62
63 1
        $this->benchmarkRoute = $this->getProfiler()->start($name, $metadata, 'Dispatcher');
64 1
    }
65
66
    /**
67
     * Stop dispatch loop benchmark
68
     */
69 1
    public function afterExecuteRoute()
70
    {
71 1
        $this->getProfiler()->stop($this->benchmarkRoute);
72 1
    }
73
}
74