1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Modules\Telescope\Providers; |
4
|
|
|
|
5
|
|
|
use Foundation\Contracts\ConditionalAutoRegistration; |
6
|
|
|
use Illuminate\Support\Facades\Gate; |
7
|
|
|
use Laravel\Telescope\EntryType; |
8
|
|
|
use Laravel\Telescope\IncomingEntry; |
9
|
|
|
use Laravel\Telescope\Telescope; |
10
|
|
|
use Laravel\Telescope\TelescopeApplicationServiceProvider; |
11
|
|
|
|
12
|
|
|
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider implements ConditionalAutoRegistration |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Register any application services. |
16
|
|
|
* |
17
|
|
|
* @return void |
18
|
|
|
*/ |
19
|
|
|
public function register() |
20
|
|
|
{ |
21
|
|
|
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class); |
22
|
|
|
|
23
|
|
|
//Telescope::night(); |
24
|
|
|
|
25
|
|
|
Telescope::filter(function (IncomingEntry $entry) { |
26
|
|
|
if (is_bool($filter = $this->filterHorizonEntries($entry))) { |
27
|
|
|
return $filter; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if (is_bool($filter = $this->filterCorsRequests($entry))) { |
31
|
|
|
return $filter; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if ($this->app->environment('local')) { |
35
|
|
|
return true; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $entry->isReportableException() || |
39
|
|
|
$entry->isFailedJob() || |
40
|
|
|
$entry->isScheduledTask() || |
41
|
|
|
$entry->hasMonitoredTag(); |
42
|
|
|
}); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function filterHorizonEntries(IncomingEntry $entry) |
46
|
|
|
{ |
47
|
|
|
if ($entry->type === EntryType::REQUEST |
48
|
|
|
&& isset($entry->content['uri']) |
49
|
|
|
&& str_contains($entry->content['uri'], 'horizon')) { |
|
|
|
|
50
|
|
|
return false; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($entry->type === EntryType::EVENT |
54
|
|
|
&& isset($entry->content['name']) |
55
|
|
|
&& str_contains($entry->content['name'], 'Horizon')) { |
|
|
|
|
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function filterCorsRequests(IncomingEntry $entry) |
61
|
|
|
{ |
62
|
|
|
if ($entry->type === EntryType::REQUEST |
63
|
|
|
&& isset($entry->content['method']) |
64
|
|
|
&& $entry->content['method'] === 'OPTIONS') { |
65
|
|
|
return false; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Register the Telescope gate. |
71
|
|
|
* |
72
|
|
|
* This gate determines who can access Telescope in non-local environments. |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
protected function gate() |
77
|
|
|
{ |
78
|
|
|
Gate::define('viewTelescope', function ($user) { |
79
|
|
|
return in_array($user->email, [ |
80
|
|
|
// |
81
|
|
|
]); |
82
|
|
|
}); |
83
|
|
|
} |
84
|
|
|
|
85
|
43 |
|
public function registrationCondition(): bool |
86
|
|
|
{ |
87
|
43 |
|
return app()->environment('local'); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.