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\Calculation\CalculationResponse; |
11
|
|
|
use VasilDakov\Speedy\Service\Client\GetContractClientsRequest; |
12
|
|
|
use VasilDakov\Speedy\Service\Client\GetContractClientsResponse; |
13
|
|
|
use VasilDakov\Speedy\Service\Location\Complex\FindComplexRequest; |
14
|
|
|
use VasilDakov\Speedy\Service\Location\Complex\FindComplexResponse; |
15
|
|
|
use VasilDakov\Speedy\Service\Location\Country\FindCountryRequest; |
16
|
|
|
use VasilDakov\Speedy\Service\Location\Country\FindCountryResponse; |
17
|
|
|
use VasilDakov\Speedy\Service\Location\Office\FindOfficeRequest; |
18
|
|
|
use VasilDakov\Speedy\Service\Location\Office\FindOfficeResponse; |
19
|
|
|
use VasilDakov\Speedy\Service\Location\Site\FindSiteRequest; |
20
|
|
|
use VasilDakov\Speedy\Service\Location\Site\FindSiteResponse; |
21
|
|
|
use VasilDakov\Speedy\Service\Location\State\FindStateRequest; |
22
|
|
|
use VasilDakov\Speedy\Service\Location\State\FindStateResponse; |
23
|
|
|
use VasilDakov\Speedy\Service\Location\Street\FindStreetRequest; |
24
|
|
|
use VasilDakov\Speedy\Service\Location\Street\FindStreetResponse; |
25
|
|
|
use VasilDakov\Speedy\Service\Printing\PrintRequest; |
26
|
|
|
use VasilDakov\Speedy\Service\Printing\PrintResponse; |
27
|
|
|
use VasilDakov\Speedy\Service\Service\DestinationServicesRequest; |
28
|
|
|
use VasilDakov\Speedy\Service\Service\DestinationServicesResponse; |
29
|
|
|
use VasilDakov\Speedy\Service\Shipment\CreateShipmentRequest; |
30
|
|
|
use VasilDakov\Speedy\Service\Shipment\CreateShipmentResponse; |
31
|
|
|
use VasilDakov\Speedy\Service\Track\TrackRequest; |
32
|
|
|
use VasilDakov\Speedy\Service\Track\TrackResponse; |
33
|
|
|
|
34
|
|
|
final class SpeedyModelDecorator implements SpeedyInterface |
35
|
|
|
{ |
36
|
|
|
private SpeedyInterface $speedy; |
37
|
|
|
|
38
|
|
|
private SerializerInterface $serializer; |
39
|
|
|
|
40
|
5 |
|
public function __construct( |
41
|
|
|
SpeedyInterface $speedy, |
42
|
|
|
SerializerInterface $serializer = null |
43
|
|
|
) { |
44
|
5 |
|
$this->speedy = $speedy; |
45
|
|
|
|
46
|
5 |
|
if (null === $serializer) { |
47
|
1 |
|
$serializer = (new SerializerFactory())(); |
48
|
|
|
} |
49
|
5 |
|
$this->serializer = $serializer; |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
public function getContractClient(GetContractClientsRequest $req): GetContractClientsResponse |
53
|
|
|
{ |
54
|
1 |
|
$json = $this->speedy->getContractClient($req); |
55
|
|
|
|
56
|
|
|
/** @var GetContractClientsResponse $response */ |
57
|
1 |
|
$response = $this->deserialize($json, GetContractClientsResponse::class); |
|
|
|
|
58
|
|
|
|
59
|
1 |
|
return $response; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
public function findCountry(FindCountryRequest $req): FindCountryResponse |
63
|
|
|
{ |
64
|
1 |
|
$json = $this->speedy->findCountry($req); |
65
|
|
|
|
66
|
|
|
/** @var GetContractClientsResponse $response */ |
67
|
1 |
|
$response = $this->deserialize(json: $json, type: FindCountryResponse::class); |
|
|
|
|
68
|
|
|
|
69
|
1 |
|
return $response; |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
1 |
|
public function findState(FindStateRequest $req): FindStateResponse |
74
|
|
|
{ |
75
|
1 |
|
$json = $this->speedy->findState($req); |
76
|
|
|
|
77
|
|
|
/** @var FindStateResponse $response */ |
78
|
1 |
|
$response = $this->deserialize(json: $json, type: FindStateResponse::class); |
|
|
|
|
79
|
|
|
|
80
|
1 |
|
return $response; |
81
|
|
|
} |
82
|
|
|
|
83
|
4 |
|
private function deserialize(string $json, string $type): object |
84
|
|
|
{ |
85
|
4 |
|
return $this->serializer->deserialize( |
86
|
4 |
|
data: $json, |
87
|
4 |
|
type: $type, |
88
|
4 |
|
format: 'json' |
89
|
4 |
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
public function findSite(FindSiteRequest $req): FindSiteResponse |
93
|
|
|
{ |
94
|
1 |
|
$json = $this->speedy->findSite($req); |
95
|
|
|
|
96
|
|
|
/** @var FindSiteResponse $response */ |
97
|
1 |
|
$response = $this->deserialize(json: $json, type: FindSiteResponse::class); |
|
|
|
|
98
|
|
|
|
99
|
1 |
|
return $response; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function findOffice(FindOfficeRequest $req): FindOfficeResponse |
103
|
|
|
{ |
104
|
|
|
$json = $this->speedy->findOffice($req); |
105
|
|
|
|
106
|
|
|
/** @var FindOfficeResponse $response */ |
107
|
|
|
$response = $this->deserialize(json: $json, type: FindOfficeResponse::class); |
|
|
|
|
108
|
|
|
|
109
|
|
|
return $response; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function findComplex(FindComplexRequest $req): FindComplexResponse |
113
|
|
|
{ |
114
|
|
|
$json = $this->speedy->findComplex($req); |
115
|
|
|
|
116
|
|
|
/** @var FindComplexResponse $response */ |
117
|
|
|
$response = $this->deserialize(json: $json, type: FindComplexResponse::class); |
|
|
|
|
118
|
|
|
|
119
|
|
|
return $response; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function findStreet(FindStreetRequest $req): FindStreetResponse |
123
|
|
|
{ |
124
|
|
|
$json = $this->speedy->findStreet($req); |
125
|
|
|
|
126
|
|
|
/** @var FindStreetResponse $response */ |
127
|
|
|
$response = $this->deserialize(json: $json, type: FindStreetResponse::class); |
|
|
|
|
128
|
|
|
|
129
|
|
|
return $response; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function createShipment(CreateShipmentRequest $req): CreateShipmentResponse |
133
|
|
|
{ |
134
|
|
|
$json = $this->speedy->createShipment($req); |
135
|
|
|
|
136
|
|
|
/** @var CreateShipmentResponse $response */ |
137
|
|
|
$response = $this->deserialize(json: $json, type: CreateShipmentResponse::class); |
|
|
|
|
138
|
|
|
|
139
|
|
|
return $response; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function track(TrackRequest $object): TrackResponse |
143
|
|
|
{ |
144
|
|
|
$json = $this->speedy->track($object); |
145
|
|
|
|
146
|
|
|
/** @var TrackResponse $response */ |
147
|
|
|
$response = $this->deserialize(json: $json, type: TrackResponse::class); |
|
|
|
|
148
|
|
|
|
149
|
|
|
return $response; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function calculate(CalculationRequest $object): CalculationResponse |
153
|
|
|
{ |
154
|
|
|
$json = $this->speedy->calculate($object); |
155
|
|
|
|
156
|
|
|
/** @var CalculationResponse $response */ |
157
|
|
|
$response = $this->deserialize(json: $json, type: CalculationResponse::class); |
|
|
|
|
158
|
|
|
|
159
|
|
|
return $response; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function print(PrintRequest $object): PrintResponse |
163
|
|
|
{ |
164
|
|
|
return new PrintResponse(); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function destination(DestinationServicesRequest $object): DestinationServicesResponse |
168
|
|
|
{ |
169
|
|
|
$json = $this->speedy->destination($object); |
170
|
|
|
|
171
|
|
|
/** @var DestinationServicesResponse $response */ |
172
|
|
|
$response = $this->deserialize(json: $json, type: DestinationServicesResponse::class); |
|
|
|
|
173
|
|
|
|
174
|
|
|
return $response; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|