Completed
Push — master ( f328e9...1657f1 )
by ARCANEDEV
13s
created

RouteEventSubscriber::handle()   A

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 1
crap 1
1
<?php namespace Arcanedev\LaravelTracker\EventListeners;
2
3
use Arcanedev\LaravelTracker\Contracts\Tracker;
4
use Illuminate\Routing\Events\RouteMatched;
5
use Illuminate\Routing\Route;
6
7
/**
8
 * Class     RouteEventSubscriber
9
 *
10
 * @package  Arcanedev\LaravelTracker\EventListeners
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class RouteEventSubscriber
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Properties
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /** @var \Arcanedev\LaravelTracker\Contracts\Tracker */
20
    private $tracker;
21
22
    /* ------------------------------------------------------------------------------------------------
23
     |  Constructor
24
     | ------------------------------------------------------------------------------------------------
25
     */
26
    /**
27
     * RouteEventSubscriber constructor.
28
     *
29
     * @param  \Arcanedev\LaravelTracker\Contracts\Tracker  $tracker
30
     */
31 198
    public function __construct(Tracker $tracker)
32
    {
33 198
        $this->tracker = $tracker;
34 198
    }
35
36
    /* ------------------------------------------------------------------------------------------------
37
     |  Main Functions
38
     | ------------------------------------------------------------------------------------------------
39
     */
40
    /**
41
     * Register the listeners for the subscriber.
42
     *
43
     * @param  \Illuminate\Events\Dispatcher  $events
44
     */
45 198
    public function subscribe($events)
46
    {
47 198
        $class = self::class;
48
49 198
        $events->listen('Illuminate\Routing\Events\RouteMatched', "$class@handle");
50 198
        $events->listen('router.matched',                         "$class@handleOldEvent");
51 198
    }
52
53
    /**
54
     * Track the matched route.
55
     *
56
     * @param  \Illuminate\Routing\Events\RouteMatched  $event
57
     */
58 4
    public function handle(RouteMatched $event)
59
    {
60 4
        $this->tracker->trackMatchedRoute($event->route, $event->request);
61 4
    }
62
63
    /**
64
     * Track the matched route (old event on Laravel 5.1).
65
     *
66
     * @param  \Illuminate\Routing\Route  $route
67
     */
68 2
    public function handleOldEvent(Route $route)
69
    {
70 2
        $this->tracker->trackMatchedRoute($route, request());
71 2
    }
72
}
73