Files
SGF/app/Providers/AppServiceProvider.php
2026-11-11 09:00:17 +02:00

48 lines
1.8 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
{
require_once base_path('packages/budget-control/bootstrap.php');
require_once base_path('packages/payables/bootstrap.php');
require_once base_path('packages/general-ledger/bootstrap.php');
if (is_file(base_path('packages/purchasing/current.json'))) {
require_once base_path('packages/purchasing/bootstrap.php');
}
$this->app->scoped(CompanyContext::class, fn () => new CompanyContext());
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
if ($routes = \App\Modules\Purchasing\InternalRequisitionQa::mount()) {
$this->loadRoutesFrom($routes);
}
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)) {
if($this->app->environment('budget-testing'))throw new \RuntimeException('SGF_COMPOSITION_DESTRUCTIVE_COMMAND_REFUSED');
$connection = $event->input->hasOption('database') ? $event->input->getOption('database') : null;
TestingDatabaseGuard::assertSafe($connection);
}
});
}
}