2023-03-17 14:33:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
use App\Models\PersonalAccessToken;
|
2025-01-06 15:24:53 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
2023-05-30 13:52:17 +00:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2023-03-17 14:33:48 +00:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2024-10-28 20:57:00 +00:00
|
|
|
use Illuminate\Validation\Rules\Password;
|
2023-10-18 16:02:09 +00:00
|
|
|
use Laravel\Sanctum\Sanctum;
|
2025-01-06 15:24:53 +00:00
|
|
|
use Laravel\Telescope\TelescopeServiceProvider;
|
2023-03-17 14:33:48 +00:00
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
2024-11-02 11:09:33 +00:00
|
|
|
public function register(): void
|
|
|
|
|
{
|
2025-01-06 15:24:53 +00:00
|
|
|
if (App::isLocal()) {
|
|
|
|
|
$this->app->register(TelescopeServiceProvider::class);
|
2024-11-02 11:09:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-17 14:33:48 +00:00
|
|
|
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
2025-01-06 15:24:53 +00:00
|
|
|
$this->configureCommands();
|
|
|
|
|
$this->configureModels();
|
|
|
|
|
$this->configurePasswords();
|
|
|
|
|
$this->configureSanctumModel();
|
|
|
|
|
$this->configureGitHubHttp();
|
2025-01-28 13:30:11 +00:00
|
|
|
|
2025-01-06 15:24:53 +00:00
|
|
|
}
|
2024-07-12 10:59:53 +00:00
|
|
|
|
2025-01-06 15:24:53 +00:00
|
|
|
private function configureCommands(): void
|
|
|
|
|
{
|
|
|
|
|
if (App::isProduction()) {
|
|
|
|
|
DB::prohibitDestructiveCommands();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function configureModels(): void
|
|
|
|
|
{
|
2025-01-16 20:07:12 +00:00
|
|
|
// Disabled because it's causing issues with the application
|
|
|
|
|
// Model::shouldBeStrict();
|
2025-01-06 15:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function configurePasswords(): void
|
|
|
|
|
{
|
2024-10-28 20:57:00 +00:00
|
|
|
Password::defaults(function () {
|
2025-01-06 15:24:53 +00:00
|
|
|
return App::isProduction()
|
2025-01-16 17:06:46 +00:00
|
|
|
? Password::min(8)
|
|
|
|
|
->mixedCase()
|
2025-01-06 15:41:05 +00:00
|
|
|
->letters()
|
2025-01-06 15:24:53 +00:00
|
|
|
->numbers()
|
|
|
|
|
->symbols()
|
|
|
|
|
->uncompromised()
|
2025-01-16 17:06:46 +00:00
|
|
|
: Password::min(8)->letters();
|
2024-10-28 20:57:00 +00:00
|
|
|
});
|
2025-01-06 15:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function configureSanctumModel(): void
|
|
|
|
|
{
|
|
|
|
|
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
|
|
|
|
|
}
|
2024-10-28 20:57:00 +00:00
|
|
|
|
2025-01-06 15:24:53 +00:00
|
|
|
private function configureGitHubHttp(): void
|
|
|
|
|
{
|
|
|
|
|
Http::macro('GitHub', function (string $api_url, ?string $github_access_token = null) {
|
2023-06-13 13:01:11 +00:00
|
|
|
if ($github_access_token) {
|
|
|
|
|
return Http::withHeaders([
|
|
|
|
|
'X-GitHub-Api-Version' => '2022-11-28',
|
|
|
|
|
'Accept' => 'application/vnd.github.v3+json',
|
|
|
|
|
'Authorization' => "Bearer $github_access_token",
|
|
|
|
|
])->baseUrl($api_url);
|
|
|
|
|
} else {
|
|
|
|
|
return Http::withHeaders([
|
|
|
|
|
'Accept' => 'application/vnd.github.v3+json',
|
|
|
|
|
])->baseUrl($api_url);
|
|
|
|
|
}
|
2023-05-30 13:52:17 +00:00
|
|
|
});
|
2023-03-17 14:33:48 +00:00
|
|
|
}
|
|
|
|
|
}
|