|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* Application Service Class |
|
5
|
|
|
* @package Ticaje_BookingApi |
|
6
|
|
|
* @author Hector Luis Barrientos <[email protected]> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Ticaje\BookingApi\Application\Service\Provider; |
|
10
|
|
|
|
|
11
|
|
|
use Exception; |
|
12
|
|
|
use Ticaje\BookingApi\Application\Signatures\Provider\DisabledDaysGatewaySignature; |
|
13
|
|
|
use Ticaje\BookingApi\Application\Signatures\Provider\DisabledDaysProviderSignature; |
|
14
|
|
|
use Ticaje\BookingApi\Domain\Policies\Calendar\Disabling\CQRS\Query; |
|
15
|
|
|
use Ticaje\BookingApi\Domain\Policies\Calendar\Disabling\CQRS\QuerySignature; |
|
16
|
|
|
use Ticaje\Contract\Application\Service\ServiceLocatorInterface; |
|
17
|
|
|
use Ticaje\Hexagonal\Application\Signatures\UseCase\UseCaseCommandInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class DisabledDaysProvider |
|
21
|
|
|
* @package Ticaje\BookingApi\Application\Service\Provider |
|
22
|
|
|
*/ |
|
23
|
|
|
class DisabledDaysProvider implements DisabledDaysProviderSignature |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var ServiceLocatorInterface */ |
|
26
|
|
|
private $serviceLocator; |
|
27
|
|
|
|
|
28
|
|
|
/** @var DisabledDaysGatewaySignature */ |
|
29
|
|
|
private $disabledDaysGatewaySignature; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* DisabledDaysProvider constructor. |
|
33
|
|
|
* |
|
34
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
35
|
|
|
* @param DisabledDaysGatewaySignature $disabledDaysGatewaySignature |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct( |
|
38
|
|
|
ServiceLocatorInterface $serviceLocator, |
|
39
|
|
|
DisabledDaysGatewaySignature $disabledDaysGatewaySignature) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->serviceLocator = $serviceLocator; |
|
42
|
|
|
$this->disabledDaysGatewaySignature = $disabledDaysGatewaySignature; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @inheritDoc |
|
47
|
|
|
*/ |
|
48
|
|
|
public function execute(UseCaseCommandInterface $command) |
|
49
|
|
|
{ |
|
50
|
|
|
$items = $this->disabledDaysGatewaySignature->execute($command); |
|
51
|
|
|
|
|
52
|
|
|
return $this->transform($items, $command->getFormat()); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param array $items |
|
57
|
|
|
* @param $format |
|
58
|
|
|
* |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
private function transform(array $items, $format): string |
|
62
|
|
|
{ |
|
63
|
|
|
/** @var QuerySignature $domainFetcher */ |
|
64
|
|
|
$domainFetcher = $this->serviceLocator->get(Query::class, ['format' => $format]); |
|
|
|
|
|
|
65
|
|
|
foreach ($items as $item) { |
|
66
|
|
|
try { |
|
67
|
|
|
$domainFetcher->interpret($item->getRule(), $item->getType()); |
|
68
|
|
|
} catch (Exception $exception) { |
|
69
|
|
|
// Log properly |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return json_encode($domainFetcher->fetchList()); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|