1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VasilDakov\Speedy; |
6
|
|
|
|
7
|
|
|
use JMS\Serializer\SerializerInterface; |
8
|
|
|
use VasilDakov\Speedy\Serializer\SerializerFactory; |
9
|
|
|
use VasilDakov\Speedy\Service\Calculation\CalculationRequest; |
10
|
|
|
use VasilDakov\Speedy\Service\Client\GetContractClientsRequest; |
11
|
|
|
use VasilDakov\Speedy\Service\Client\GetContractClientsResponse; |
12
|
|
|
use VasilDakov\Speedy\Service\Location\Complex\FindComplexRequest; |
13
|
|
|
use VasilDakov\Speedy\Service\Location\Country\FindCountryRequest; |
14
|
|
|
use VasilDakov\Speedy\Service\Location\Country\FindCountryResponse; |
15
|
|
|
use VasilDakov\Speedy\Service\Location\Office\FindOfficeRequest; |
16
|
|
|
use VasilDakov\Speedy\Service\Location\Site\FindSiteRequest; |
17
|
|
|
use VasilDakov\Speedy\Service\Location\State\FindStateRequest; |
18
|
|
|
use VasilDakov\Speedy\Service\Location\State\FindStateResponse; |
19
|
|
|
use VasilDakov\Speedy\Service\Location\Street\FindStreetRequest; |
20
|
|
|
use VasilDakov\Speedy\Service\Printing\PrintRequest; |
21
|
|
|
use VasilDakov\Speedy\Service\Printing\PrintResponse; |
22
|
|
|
use VasilDakov\Speedy\Service\Service\DestinationServicesRequest; |
23
|
|
|
use VasilDakov\Speedy\Service\Shipment\CreateShipmentRequest; |
24
|
|
|
use VasilDakov\Speedy\Service\Track\TrackRequest; |
25
|
|
|
|
26
|
|
|
final class SpeedyModelDecorator implements SpeedyInterface |
27
|
|
|
{ |
28
|
|
|
private SpeedyInterface $speedy; |
29
|
|
|
|
30
|
|
|
private SerializerInterface $serializer; |
31
|
|
|
|
32
|
4 |
|
public function __construct(SpeedyInterface $speedy, SerializerInterface $serializer = null) |
33
|
|
|
{ |
34
|
4 |
|
$this->speedy = $speedy; |
35
|
|
|
|
36
|
4 |
|
if (null === $serializer) { |
37
|
1 |
|
$serializer = (new SerializerFactory())(); |
38
|
|
|
} |
39
|
4 |
|
$this->serializer = $serializer; |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
public function getContractClient(GetContractClientsRequest $req): GetContractClientsResponse |
43
|
|
|
{ |
44
|
1 |
|
$json = $this->speedy->getContractClient($req); |
45
|
|
|
|
46
|
|
|
/** @var GetContractClientsResponse $response */ |
47
|
1 |
|
$response = $this->deserialize($json, GetContractClientsResponse::class); |
|
|
|
|
48
|
|
|
|
49
|
1 |
|
return $response; |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
public function findCountry(FindCountryRequest $req): FindCountryResponse |
53
|
|
|
{ |
54
|
1 |
|
$json = $this->speedy->findCountry($req); |
55
|
|
|
|
56
|
|
|
/** @var GetContractClientsResponse $response */ |
57
|
1 |
|
$response = $this->deserialize(json: $json, type: FindCountryResponse::class); |
|
|
|
|
58
|
|
|
|
59
|
1 |
|
return $response; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
1 |
|
public function findState(FindStateRequest $req): FindStateResponse |
64
|
|
|
{ |
65
|
1 |
|
$json = $this->speedy->findState($req); |
66
|
|
|
|
67
|
|
|
/** @var FindStateResponse $response */ |
68
|
1 |
|
$response = $this->deserialize(json: $json, type: FindStateResponse::class); |
|
|
|
|
69
|
|
|
|
70
|
1 |
|
return $response; |
71
|
|
|
} |
72
|
|
|
|
73
|
3 |
|
private function deserialize(string $json, string $type): object |
74
|
|
|
{ |
75
|
3 |
|
return $this->serializer->deserialize( |
76
|
3 |
|
data: $json, |
77
|
3 |
|
type: $type, |
78
|
3 |
|
format: 'json' |
79
|
3 |
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function findSite(FindSiteRequest $req): string|object |
83
|
|
|
{ |
84
|
|
|
// TODO: Implement findSite() method. |
85
|
|
|
} |
|
|
|
|
86
|
|
|
|
87
|
|
|
public function findOffice(FindOfficeRequest $req): string|object |
88
|
|
|
{ |
89
|
|
|
// TODO: Implement findOffice() method. |
90
|
|
|
} |
|
|
|
|
91
|
|
|
|
92
|
|
|
public function findComplex(FindComplexRequest $req): string|object |
93
|
|
|
{ |
94
|
|
|
// TODO: Implement findComplex() method. |
95
|
|
|
} |
|
|
|
|
96
|
|
|
|
97
|
|
|
public function findStreet(FindStreetRequest $req): string|object |
98
|
|
|
{ |
99
|
|
|
// TODO: Implement findStreet() method. |
100
|
|
|
} |
|
|
|
|
101
|
|
|
|
102
|
|
|
public function createShipment(CreateShipmentRequest $req): string|object |
103
|
|
|
{ |
104
|
|
|
// TODO: Implement createShipment() method. |
105
|
|
|
} |
|
|
|
|
106
|
|
|
|
107
|
|
|
public function track(TrackRequest $object): string|object |
108
|
|
|
{ |
109
|
|
|
// TODO: Implement track() method. |
110
|
|
|
} |
|
|
|
|
111
|
|
|
|
112
|
|
|
public function calculate(CalculationRequest $object): string|object |
113
|
|
|
{ |
114
|
|
|
// TODO: Implement calculate() method. |
115
|
|
|
} |
|
|
|
|
116
|
|
|
|
117
|
|
|
public function print(PrintRequest $object): PrintResponse |
118
|
|
|
{ |
119
|
|
|
return new PrintResponse(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function destination(DestinationServicesRequest $object): string|object |
123
|
|
|
{ |
124
|
|
|
// TODO: Implement destination() method. |
125
|
|
|
} |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|