86 lines
3.0 KiB
PHP
86 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Services\AdministrativeGeography;
|
|
use App\Services\BudgetDistributionArtifact;
|
|
use App\Services\FinanceBundle;
|
|
use App\Services\ReplenishmentRun;
|
|
use App\Services\RequisitionExpiryRun;
|
|
use App\Services\StandaloneArtifact;
|
|
use App\Services\StandaloneRuntime;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Support\Facades\Date;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
$this->app->singleton(ReplenishmentRun::class);
|
|
$this->app->singleton(RequisitionExpiryRun::class);
|
|
$this->app->scoped(AdministrativeGeography::class);
|
|
$this->app->scoped(StandaloneRuntime::class, fn () => new StandaloneRuntime(config('standalone-runtime'), new StandaloneArtifact));
|
|
$runtime = $this->app->make(StandaloneRuntime::class);
|
|
$paths = null;
|
|
if ($runtime->enabled()) {
|
|
if (config('common-finance-bundle.root') !== null || config('budget-distributions.enabled') === true) {
|
|
throw new \LogicException('COMPRAS_RUNTIME_MIXED_COMPOSITION');
|
|
}
|
|
$paths = $runtime->configure(DB::connection());
|
|
$runtime->assertLoadedPackages(allowMissing: true);
|
|
config(['common-budget.path' => $paths['budget-control'], 'common-payables.path' => $paths['payables'],
|
|
'general-ledger.path' => $paths['general-ledger']]);
|
|
}
|
|
require_once ($paths['purchasing'] ?? config('common-purchasing.path')).'/bootstrap.php';
|
|
$package = config('common-budget.path');
|
|
if (config('budget-distributions.enabled') === true) {
|
|
BudgetDistributionArtifact::verify($package,
|
|
config('budget-distributions.artifact_manifest'), config('budget-distributions.artifact_manifest_sha256'));
|
|
}
|
|
require_once $package.'/bootstrap.php';
|
|
FinanceBundle::configure();
|
|
$payables = config('common-payables.path');
|
|
require_once $payables.'/bootstrap.php';
|
|
if ($paths !== null) {
|
|
require_once $paths['general-ledger'].'/bootstrap.php';
|
|
$runtime->assertLoadedPackages();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
$this->configureDefaults();
|
|
}
|
|
|
|
/**
|
|
* Configure default behaviors for production-ready applications.
|
|
*/
|
|
protected function configureDefaults(): void
|
|
{
|
|
Date::use(CarbonImmutable::class);
|
|
|
|
DB::prohibitDestructiveCommands(
|
|
app()->isProduction(),
|
|
);
|
|
|
|
Password::defaults(fn (): ?Password => app()->isProduction()
|
|
? Password::min(12)
|
|
->mixedCase()
|
|
->letters()
|
|
->numbers()
|
|
->symbols()
|
|
->uncompromised()
|
|
: null,
|
|
);
|
|
}
|
|
}
|