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
|
|
|
|
20
|
|
|
/** @var \Arcanedev\LaravelTracker\Contracts\Tracker */ |
21
|
|
|
private $tracker; |
22
|
|
|
|
23
|
|
|
/* ----------------------------------------------------------------- |
24
|
|
|
| Constructor |
25
|
|
|
| ----------------------------------------------------------------- |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* RouteEventSubscriber constructor. |
30
|
|
|
* |
31
|
|
|
* @param \Arcanedev\LaravelTracker\Contracts\Tracker $manager |
32
|
|
|
*/ |
33
|
117 |
|
public function __construct(Tracker $manager) |
34
|
|
|
{ |
35
|
117 |
|
$this->tracker = $manager; |
36
|
117 |
|
} |
37
|
|
|
|
38
|
|
|
/* ----------------------------------------------------------------- |
39
|
|
|
| Main Methods |
40
|
|
|
| ----------------------------------------------------------------- |
41
|
|
|
*/ |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Register the listeners for the subscriber. |
45
|
|
|
* |
46
|
|
|
* @param \Illuminate\Events\Dispatcher $events |
47
|
|
|
*/ |
48
|
117 |
|
public function subscribe($events) |
49
|
|
|
{ |
50
|
117 |
|
$class = self::class; |
51
|
|
|
|
52
|
117 |
|
$events->listen(RouteMatched::class, "$class@handle"); |
53
|
117 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Track the matched route. |
57
|
|
|
* |
58
|
|
|
* @param \Illuminate\Routing\Events\RouteMatched $event |
59
|
|
|
*/ |
60
|
6 |
|
public function handle(RouteMatched $event) |
61
|
|
|
{ |
62
|
6 |
|
$this->tracker->trackMatchedRoute($event->route, $event->request); |
63
|
6 |
|
} |
64
|
|
|
} |
65
|
|
|
|