43 lines
1.4 KiB
PHP
43 lines
1.4 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');
|
|
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 ($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);
|
|
}
|
|
});
|
|
}
|
|
}
|