1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TK\API\ValueObject; |
5
|
|
|
|
6
|
|
|
use TK\API\Exception\InvalidArgumentException; |
7
|
|
|
|
8
|
|
|
final class OriginDestinationInformation implements ValueObjectInterface |
9
|
|
|
{ |
10
|
|
|
public const CABIN_PREFERENCE_ECONOMY = 'ECONOMY'; |
11
|
|
|
public const CABIN_PREFERENCE_BUSINESS = 'BUSINESS'; |
12
|
|
|
|
13
|
|
|
private static $cabinPreferencesEnum = ['ECONOMY', 'BUSINESS']; |
14
|
|
|
|
15
|
|
|
private $departureDateTime; |
16
|
|
|
private $originLocation; |
17
|
|
|
private $destinationLocation; |
18
|
|
|
private $cabinPreferences = []; |
19
|
|
|
|
20
|
|
|
public function __construct( |
21
|
|
|
DepartureDateTime $departureDateTime, |
22
|
|
|
Location $originLocation, |
23
|
|
|
Location $destinationLocation |
24
|
|
|
) { |
25
|
|
|
$this->departureDateTime = $departureDateTime; |
26
|
|
|
$this->originLocation = $originLocation; |
27
|
|
|
$this->destinationLocation = $destinationLocation; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function withCabinPreferences(string $cabinPreference) : OriginDestinationInformation |
31
|
|
|
{ |
32
|
|
|
if (!\in_array($cabinPreference, self::$cabinPreferencesEnum, true)) { |
33
|
|
|
throw new InvalidArgumentException( |
34
|
|
|
'Invalid value for OriginDestinationInformation.CabinPreferences. Use one of these: ' . |
35
|
|
|
implode(', ', self::$cabinPreferencesEnum) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
$this->cabinPreferences[] = $cabinPreference; |
39
|
|
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getValue() : array |
43
|
|
|
{ |
44
|
|
|
$originDestinationInformationValue = [ |
45
|
|
|
'DepartureDateTime' => $this->departureDateTime->getValue(), |
46
|
|
|
'OriginLocation' => $this->originLocation->getValue(), |
47
|
|
|
'DestinationLocation' => $this->destinationLocation->getValue() |
48
|
|
|
]; |
49
|
|
|
if (\count($this->cabinPreferences) !== 0) { |
50
|
|
|
$originDestinationInformationValue['CabinPreferences'] = []; |
51
|
|
|
foreach ($this->cabinPreferences as $cabinPreference) { |
52
|
|
|
$originDestinationInformationValue['CabinPreferences'][] = ['Cabin' => $cabinPreference]; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
return $originDestinationInformationValue; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|