1 | <?php |
||
12 | class SlowQueryServiceProvider extends ServiceProvider |
||
13 | { |
||
14 | /** |
||
15 | * Bootstrap the application services. |
||
16 | */ |
||
17 | public function boot() |
||
18 | { |
||
19 | $this->publishes([ |
||
20 | __DIR__ . '/../config/slow-query.php' => config_path('slow-query.php'), |
||
21 | ], 'config'); |
||
22 | |||
23 | $this->setupEvents($this->app->events); |
||
|
|||
24 | } |
||
25 | |||
26 | public function register() |
||
27 | { |
||
28 | $this->mergeConfigFrom(__DIR__ . '/../config/slow-query.php', 'slow-query'); |
||
29 | } |
||
30 | |||
31 | public function setupEvents($events) |
||
32 | { |
||
33 | $events->listen(QueryExecuted::class, function (QueryExecuted $query) { |
||
34 | if ($this->slowQueryCheck($query)) { |
||
35 | event(new QueryExecutedSlowly($query)); |
||
36 | } |
||
37 | }); |
||
38 | |||
39 | $events->listen(QueryExecutedSlowly::class, function (QueryExecutedSlowly $event) { |
||
40 | $provider = Config::get('slow-query.notifications.default'); |
||
41 | $channel = Config::get('slow-query.notifications.' . $provider . '.channel'); |
||
42 | |||
43 | Notification::route($provider, $channel) |
||
44 | ->notify(new SlowQueryDetected($event->query)); |
||
45 | }); |
||
46 | } |
||
47 | |||
48 | public function slowQueryCheck(QueryExecuted $query) |
||
52 | } |
||
53 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: