Files
SGF/app/Providers/AppServiceProvider.php
T

38 lines
1.2 KiB
PHP

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Shared\Context\CompanyContext;
use App\Shared\Testing\TestingDatabaseGuard;
use Illuminate\Console\Events\CommandStarting;
use Illuminate\Support\Facades\Event;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
$this->app->scoped(CompanyContext::class, fn () => new CompanyContext());
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
if ($this->app->environment(['testing', 'browser-testing']) || defined('PHPUNIT_COMPOSER_INSTALL')) {
TestingDatabaseGuard::assertSafe();
}
Event::listen(CommandStarting::class, function (CommandStarting $event): void {
if (in_array($event->command, ['migrate:fresh', 'migrate:refresh', 'migrate:reset', 'migrate:rollback', 'db:wipe'], true)) {
$connection = $event->input->hasOption('database') ? $event->input->getOption('database') : null;
TestingDatabaseGuard::assertSafe($connection);
}
});
}
}