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