ldc-legaulois/app/Providers/TelescopeServiceProvider.php
2024-10-24 09:03:17 +00:00

81 lines
2 KiB
PHP

<?php
namespace App\Providers;
use App\Enums\Theme\BootstrapThemeEnum;
use Illuminate\Support\Facades\Gate;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeApplicationServiceProvider;
use Illuminate\Support\Facades\Cache;
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(): void
{
// Matches Telescope theme with back-end theme.
if (Cache::get('theme', BootstrapThemeEnum::light->value()) === BootstrapThemeEnum::dark->value()) {
Telescope::night();
}
$this->authorization();
}
/**
* Register any application services.
*
* @return void
*/
public function register(): void
{
$this->hideSensitiveRequestDetails();
$isLocal = $this->app->environment('local');
Telescope::filter(function (IncomingEntry $entry) use ($isLocal) {
return $isLocal ||
$entry->isReportableException() ||
$entry->isFailedRequest() ||
$entry->isFailedJob() ||
$entry->isScheduledTask() ||
$entry->hasMonitoredTag();
});
}
/**
* Prevent sensitive request details from being logged by Telescope.
*
* @return void
*/
protected function hideSensitiveRequestDetails(): void
{
if ($this->app->environment('local')) {
return;
}
Telescope::hideRequestParameters(['_token']);
Telescope::hideRequestHeaders([
'cookie',
'x-csrf-token',
'x-xsrf-token',
]);
}
/**
* Register the Telescope gate.
* This gate determines who can access Telescope in non-local environments.
*
* @return void
*/
protected function gate(): void
{
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, []);
});
}
}