|
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 ($entry->type === EntryType::REQUEST |
|
27
|
|
|
&& isset($entry->content['uri']) |
|
28
|
|
|
&& str_contains($entry->content['uri'], 'horizon')) { |
|
29
|
|
|
return false; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if ($entry->type === EntryType::EVENT |
|
33
|
|
|
&& isset($entry->content['name']) |
|
34
|
|
|
&& str_contains($entry->content['name'], 'Horizon')) { |
|
35
|
|
|
return false; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if ($entry->type === EntryType::REQUEST |
|
39
|
|
|
&& isset($entry->content['method']) |
|
40
|
|
|
&& $entry->content['method'] ==='OPTIONS'){ |
|
41
|
|
|
return false; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if ($this->app->environment('local')) { |
|
45
|
|
|
return true; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $entry->isReportableException() || |
|
49
|
|
|
$entry->isFailedJob() || |
|
50
|
|
|
$entry->isScheduledTask() || |
|
51
|
|
|
$entry->hasMonitoredTag(); |
|
52
|
|
|
}); |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Register the Telescope gate. |
|
59
|
|
|
* |
|
60
|
|
|
* This gate determines who can access Telescope in non-local environments. |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function gate() |
|
65
|
|
|
{ |
|
66
|
|
|
Gate::define('viewTelescope', function ($user) { |
|
67
|
|
|
return in_array($user->email, [ |
|
68
|
|
|
// |
|
69
|
|
|
]); |
|
70
|
|
|
}); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function registrationCondition(): bool |
|
74
|
|
|
{ |
|
75
|
|
|
return env('APP_ENV') === 'local'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|