auditionadmin/app/Providers/InvoiceDataServiceProvider.php

48 lines
1.4 KiB
PHP

<?php
namespace App\Providers;
use App\Services\EntryService;
use App\Services\Invoice\InvoiceDataService;
use App\Services\Invoice\InvoiceOneFeePerEntry;
use App\Services\Invoice\InvoiceOneFeePerStudent;
use Illuminate\Support\ServiceProvider;
use function auditionSetting;
/**
* @codeCoverageIgnore
*/
// TODO: Consider testing later
class InvoiceDataServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
$this->app->singleton(InvoiceDataService::class, function ($app) {
// Default binding, can be overridden in booth method
return new InvoiceOneFeePerEntry($app->make(EntryService::class));
});
}
/**
* Bootstrap services.
*/
public function boot(): void
{
if (! app()->environment('testing')) {
if (auditionSetting('fee_structure')) {
$this->app->singleton(InvoiceDataService::class, function ($app) {
return match (auditionSetting('fee_structure')) {
'oneFeePerEntry' => new InvoiceOneFeePerEntry($app->make(EntryService::class)),
'oneFeePerStudent' => new InvoiceOneFeePerStudent($app->make(EntryService::class)),
default => throw new \Exception('Unknown Invoice Method'),
};
});
}
}
}
}