feat(services): add working day determiner factory
This commit is contained in:
parent
78bb9e6f09
commit
488049d56f
32
app/Services/WorkingDays/WorkingDayDeterminerFactory.php
Normal file
32
app/Services/WorkingDays/WorkingDayDeterminerFactory.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\WorkingDays;
|
||||
|
||||
use App\Services\WorkingDays\Date\MonToFriWorkingDayDeterminer;
|
||||
use App\Services\WorkingDays\PublicHolidays\PublicHolidaysStateFactory;
|
||||
use App\Services\WorkingDays\Utils\MultipleWorkingDayDeterminer;
|
||||
|
||||
class WorkingDayDeterminerFactory
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PublicHolidaysStateFactory $publicHolidaysStateFactory,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a working day determiner for the given country.
|
||||
* @param string $countryCode
|
||||
* @return WorkingDayDeterminerInterface
|
||||
*/
|
||||
public function createForCountry(string $countryCode): WorkingDayDeterminerInterface
|
||||
{
|
||||
return match ($countryCode) {
|
||||
'CZ' => new MultipleWorkingDayDeterminer(
|
||||
[ new MonToFriWorkingDayDeterminer(), $this->publicHolidaysStateFactory->createDeterminerForCountry($countryCode) ],
|
||||
),
|
||||
default => throw new \InvalidArgumentException('Unsupported country code'),
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user