mirror of
https://github.com/coollabsio/coolify.git
synced 2026-03-11 08:55:47 +00:00
chore: add strict AppServiceProvider
This commit is contained in:
parent
a17caf0b68
commit
2d0dd50063
1 changed files with 99 additions and 2 deletions
|
|
@ -1,10 +1,22 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Facades\Vite;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
final class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
|
|
@ -16,6 +28,91 @@ class AppServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
$this->configureHttps();
|
||||
$this->configurePasswordValidation();
|
||||
$this->configureCommands();
|
||||
$this->configureModels();
|
||||
$this->configureDates();
|
||||
$this->configureRequestExceptions();
|
||||
$this->configureVite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure HTTPS for production.
|
||||
*/
|
||||
private function configureHttps(): void
|
||||
{
|
||||
if (App::isProduction() && (bool) config('app.force_https')) {
|
||||
URL::forceScheme('https');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure password validation for production.
|
||||
*/
|
||||
private function configurePasswordValidation(): void
|
||||
{
|
||||
if (App::isProduction()) {
|
||||
Password::defaults(fn () => Password::min(12)
|
||||
->letters()
|
||||
->mixedCase()
|
||||
->numbers()
|
||||
->symbols()
|
||||
->uncompromised());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure commands for production.
|
||||
*/
|
||||
private function configureCommands(): void
|
||||
{
|
||||
if (App::isProduction()) {
|
||||
DB::prohibitDestructiveCommands();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure models.
|
||||
*/
|
||||
private function configureModels(): void
|
||||
{
|
||||
if (! App::isProduction()) {
|
||||
Model::preventLazyLoading();
|
||||
}
|
||||
|
||||
Model::preventAccessingMissingAttributes();
|
||||
Model::unguard();
|
||||
|
||||
Relation::enforceMorphMap([
|
||||
// Add you polymorphic relations here. For example:
|
||||
// 'application' => \App\Models\Application::class,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure dates.
|
||||
*/
|
||||
private function configureDates(): void
|
||||
{
|
||||
Date::use(CarbonImmutable::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure request exceptions.
|
||||
*/
|
||||
private function configureRequestExceptions(): void
|
||||
{
|
||||
if (! App::isProduction()) {
|
||||
RequestException::dontTruncate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure Vite for better performance.
|
||||
*/
|
||||
private function configureVite(): void
|
||||
{
|
||||
Vite::useAggressivePrefetching();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue