|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* amadeus-ws-client |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright 2015 Amadeus Benelux NV |
|
6
|
|
|
* |
|
7
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
8
|
|
|
* you may not use this file except in compliance with the License. |
|
9
|
|
|
* You may obtain a copy of the License at |
|
10
|
|
|
* |
|
11
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
12
|
|
|
* |
|
13
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
14
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
15
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
16
|
|
|
* See the License for the specific language governing permissions and |
|
17
|
|
|
* limitations under the License. |
|
18
|
|
|
* |
|
19
|
|
|
* @package Amadeus |
|
20
|
|
|
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0 |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace Amadeus\Client\RequestCreator; |
|
24
|
|
|
|
|
25
|
|
|
use Amadeus\Client\InvalidMessageException; |
|
26
|
|
|
use Amadeus\Client\Params\RequestCreatorParams; |
|
27
|
|
|
use Amadeus\Client\RequestOptions\CommandCrypticOptions; |
|
28
|
|
|
use Amadeus\Client\RequestOptions\DocIssuanceIssueTicketOptions; |
|
29
|
|
|
use Amadeus\Client\RequestOptions\InfoEncodeDecodeCityOptions; |
|
30
|
|
|
use Amadeus\Client\RequestOptions\MiniRuleGetFromPricingRecOptions; |
|
31
|
|
|
use Amadeus\Client\RequestOptions\OfferConfirmAirOptions; |
|
32
|
|
|
use Amadeus\Client\RequestOptions\OfferConfirmCarOptions; |
|
33
|
|
|
use Amadeus\Client\RequestOptions\OfferConfirmHotelOptions; |
|
34
|
|
|
use Amadeus\Client\RequestOptions\OfferVerifyOptions; |
|
35
|
|
|
use Amadeus\Client\RequestOptions\PriceXplorerExtremeSearchOptions; |
|
36
|
|
|
use Amadeus\Client\RequestOptions\RequestOptionsInterface; |
|
37
|
|
|
use Amadeus\Client\RequestOptions\SalesReportsDisplayQueryReportOptions; |
|
38
|
|
|
use Amadeus\Client\RequestOptions\SecurityAuthenticateOptions; |
|
39
|
|
|
use Amadeus\Client\RequestOptions\TicketCreateTstFromPricingOptions; |
|
40
|
|
|
use Amadeus\Client\RequestOptions\TicketDeleteTstOptions; |
|
41
|
|
|
use Amadeus\Client\RequestOptions\TicketDisplayTstOptions; |
|
42
|
|
|
use Amadeus\Client\Struct; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Base request creator - the default request creator. |
|
46
|
|
|
* |
|
47
|
|
|
* @package Amadeus\Client\RequestCreator |
|
48
|
|
|
* @author Dieter Devlieghere <[email protected]> |
|
49
|
|
|
*/ |
|
50
|
|
|
class Base implements RequestCreatorInterface |
|
51
|
|
|
{ |
|
52
|
|
|
/** |
|
53
|
|
|
* @var RequestCreatorParams |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $params; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Associative array of messages (as keys) and versions (as values) that are present in the WSDL. |
|
59
|
|
|
* |
|
60
|
|
|
* @var array |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $messagesAndVersions = []; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param $params |
|
66
|
|
|
*/ |
|
67
|
|
|
public function __construct(RequestCreatorParams $params) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->params = $params; |
|
70
|
|
|
$this->messagesAndVersions = $params->messagesAndVersions; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $messageName the message name as named in the WSDL |
|
75
|
|
|
* @param RequestOptionsInterface $params |
|
76
|
|
|
* @throws Struct\InvalidArgumentException When invalid input is detected during message creation. |
|
77
|
|
|
* @throws InvalidMessageException when trying to create a request for a message that is not in your WSDL. |
|
78
|
|
|
* @return mixed the created request |
|
79
|
|
|
*/ |
|
80
|
|
|
public function createRequest($messageName, RequestOptionsInterface $params) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->checkMessageIsInWsdl($messageName); |
|
83
|
|
|
|
|
84
|
|
|
$builder = $this->findBuilderForMessage($messageName); |
|
85
|
|
|
|
|
86
|
|
|
$methodName = 'create' . str_replace("_", "", $messageName); |
|
87
|
|
|
|
|
88
|
|
|
if (method_exists($builder, $methodName)) { |
|
89
|
|
|
return $builder->$methodName($params, $this->getActiveVersionFor($messageName)); |
|
90
|
|
|
} else { |
|
91
|
|
|
throw new \RuntimeException('Message ' . $methodName . ' is not implemented in ' . __CLASS__); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return Struct\Security\SignOut |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function createSecuritySignOut() |
|
99
|
|
|
{ |
|
100
|
|
|
return new Struct\Security\SignOut(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Create request object for Security_Authenticate message |
|
105
|
|
|
* |
|
106
|
|
|
* @param SecurityAuthenticateOptions $params |
|
107
|
|
|
* @return Struct\Security\Authenticate |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function createSecurityAuthenticate(SecurityAuthenticateOptions $params) |
|
110
|
|
|
{ |
|
111
|
|
|
return new Struct\Security\Authenticate($params); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param OfferVerifyOptions $params |
|
116
|
|
|
* @return Struct\Offer\Verify |
|
117
|
|
|
*/ |
|
118
|
|
|
protected function createOfferVerifyOffer(OfferVerifyOptions $params) |
|
119
|
|
|
{ |
|
120
|
|
|
$req = new Struct\Offer\Verify( |
|
121
|
|
|
$params->offerReference, |
|
122
|
|
|
$params->segmentName |
|
123
|
|
|
); |
|
124
|
|
|
|
|
125
|
|
|
return $req; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param OfferConfirmAirOptions $params |
|
130
|
|
|
* @return Struct\Offer\ConfirmAir |
|
131
|
|
|
*/ |
|
132
|
|
|
protected function createOfferConfirmAirOffer(OfferConfirmAirOptions $params) |
|
133
|
|
|
{ |
|
134
|
|
|
return new Struct\Offer\ConfirmAir($params); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @param OfferConfirmHotelOptions $params |
|
140
|
|
|
* @return Struct\Offer\ConfirmHotel |
|
141
|
|
|
*/ |
|
142
|
|
|
protected function createOfferConfirmHotelOffer(OfferConfirmHotelOptions $params) |
|
143
|
|
|
{ |
|
144
|
|
|
return new Struct\Offer\ConfirmHotel($params); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param OfferConfirmCarOptions $params |
|
149
|
|
|
* @return Struct\Offer\ConfirmCar |
|
150
|
|
|
*/ |
|
151
|
|
|
protected function createOfferConfirmCarOffer(OfferConfirmCarOptions $params) |
|
152
|
|
|
{ |
|
153
|
|
|
return new Struct\Offer\ConfirmCar($params); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Command_Cryptic |
|
158
|
|
|
* |
|
159
|
|
|
* @param CommandCrypticOptions $params |
|
160
|
|
|
* @return Struct\Command\Cryptic |
|
161
|
|
|
*/ |
|
162
|
|
|
protected function createCommandCryptic(CommandCrypticOptions $params) |
|
163
|
|
|
{ |
|
164
|
|
|
return new Struct\Command\Cryptic($params->entry); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Info_EncodeDecodeCity |
|
169
|
|
|
* |
|
170
|
|
|
* @param InfoEncodeDecodeCityOptions $params |
|
171
|
|
|
* @return Struct\Info\EncodeDecodeCity |
|
172
|
|
|
*/ |
|
173
|
|
|
protected function createInfoEncodeDecodeCity(InfoEncodeDecodeCityOptions $params) |
|
174
|
|
|
{ |
|
175
|
|
|
return new Struct\Info\EncodeDecodeCity($params); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* makeMiniRuleGetFromPricingRec |
|
180
|
|
|
* |
|
181
|
|
|
* @param MiniRuleGetFromPricingRecOptions $params |
|
182
|
|
|
* @return Struct\MiniRule\GetFromPricingRec |
|
183
|
|
|
*/ |
|
184
|
|
|
protected function createMiniRuleGetFromPricingRec(MiniRuleGetFromPricingRecOptions $params) |
|
185
|
|
|
{ |
|
186
|
|
|
return new Struct\MiniRule\GetFromPricingRec($params); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Ticket_CreateTstFromPricing |
|
191
|
|
|
* |
|
192
|
|
|
* @param TicketCreateTstFromPricingOptions $params |
|
193
|
|
|
* @return Struct\Ticket\CreateTSTFromPricing |
|
194
|
|
|
*/ |
|
195
|
|
|
protected function createTicketCreateTSTFromPricing(TicketCreateTstFromPricingOptions $params) |
|
196
|
|
|
{ |
|
197
|
|
|
return new Struct\Ticket\CreateTSTFromPricing($params); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* Ticket_DeleteTST |
|
202
|
|
|
* |
|
203
|
|
|
* @param TicketDeleteTstOptions $params |
|
204
|
|
|
* @return Struct\Ticket\DeleteTST |
|
205
|
|
|
*/ |
|
206
|
|
|
protected function createTicketDeleteTST(TicketDeleteTstOptions $params) |
|
207
|
|
|
{ |
|
208
|
|
|
return new Struct\Ticket\DeleteTST($params); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Ticket_DisplayTST |
|
213
|
|
|
* |
|
214
|
|
|
* @param TicketDisplayTstOptions $params |
|
215
|
|
|
* @return Struct\Ticket\DisplayTST |
|
216
|
|
|
*/ |
|
217
|
|
|
protected function createTicketDisplayTST(TicketDisplayTstOptions $params) |
|
218
|
|
|
{ |
|
219
|
|
|
return new Struct\Ticket\DisplayTST($params); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* DocIssuance_IssueTicket |
|
224
|
|
|
* |
|
225
|
|
|
* @param DocIssuanceIssueTicketOptions $params |
|
226
|
|
|
* @return Struct\DocIssuance\IssueTicket |
|
227
|
|
|
*/ |
|
228
|
|
|
protected function createDocIssuanceIssueTicket(DocIssuanceIssueTicketOptions $params) |
|
229
|
|
|
{ |
|
230
|
|
|
return new Struct\DocIssuance\IssueTicket($params); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* PriceXplorer_ExtremeSearch |
|
235
|
|
|
* |
|
236
|
|
|
* @param PriceXplorerExtremeSearchOptions $params |
|
237
|
|
|
* @return Struct\PriceXplorer\ExtremeSearch |
|
238
|
|
|
*/ |
|
239
|
|
|
protected function createPriceXplorerExtremeSearch(PriceXplorerExtremeSearchOptions $params) |
|
240
|
|
|
{ |
|
241
|
|
|
return new Struct\PriceXplorer\ExtremeSearch($params); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* SalesReports_DisplayQueryReport |
|
246
|
|
|
* |
|
247
|
|
|
* @param SalesReportsDisplayQueryReportOptions $params |
|
248
|
|
|
* @return Struct\SalesReports\DisplayQueryReport |
|
249
|
|
|
*/ |
|
250
|
|
|
protected function createSalesReportsDisplayQueryReport(SalesReportsDisplayQueryReportOptions $params) |
|
251
|
|
|
{ |
|
252
|
|
|
return new Struct\SalesReports\DisplayQueryReport($params); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Check if a given message is in the active WSDL. Throws exception if it isn't. |
|
257
|
|
|
* |
|
258
|
|
|
* @throws InvalidMessageException if message is not in WSDL. |
|
259
|
|
|
* @param string $messageName |
|
260
|
|
|
*/ |
|
261
|
|
|
protected function checkMessageIsInWsdl($messageName) |
|
262
|
|
|
{ |
|
263
|
|
|
if (!array_key_exists($messageName, $this->messagesAndVersions)) { |
|
264
|
|
|
throw new InvalidMessageException('Message "' . $messageName . '" is not in WDSL'); |
|
265
|
|
|
} |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* Get the version number active in the WSDL for the given message |
|
270
|
|
|
* |
|
271
|
|
|
* @param string $messageName |
|
272
|
|
|
* @return float|string |
|
273
|
|
|
*/ |
|
274
|
|
|
protected function getActiveVersionFor($messageName) |
|
275
|
|
|
{ |
|
276
|
|
|
return $this->messagesAndVersions[$messageName]; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Find the correct builder for a given message |
|
281
|
|
|
* |
|
282
|
|
|
* Message build methods in all builders must adhere to the |
|
283
|
|
|
* 'create'<message name without underscores> logic as used in createRequest method. |
|
284
|
|
|
* |
|
285
|
|
|
* @param string $messageName |
|
286
|
|
|
* @return Base|Fare|Pnr |
|
|
|
|
|
|
287
|
|
|
*/ |
|
288
|
|
|
protected function findBuilderForMessage($messageName) |
|
289
|
|
|
{ |
|
290
|
|
|
$builder = null; |
|
|
|
|
|
|
291
|
|
|
|
|
292
|
|
|
$section = strtolower(substr($messageName, 0, strpos($messageName, '_'))); |
|
293
|
|
|
|
|
294
|
|
|
switch ($section) { |
|
295
|
|
|
case 'fare': |
|
296
|
|
|
$builder = new Fare(); |
|
297
|
|
|
break; |
|
298
|
|
|
case 'pnr': |
|
299
|
|
|
$builder = new Pnr($this->params); |
|
300
|
|
|
break; |
|
301
|
|
|
case 'air': |
|
302
|
|
|
$builder = new Air(); |
|
303
|
|
|
break; |
|
304
|
|
|
case 'queue': |
|
305
|
|
|
$builder = new Queue(); |
|
306
|
|
|
break; |
|
307
|
|
|
default: |
|
308
|
|
|
$builder = $this; |
|
309
|
|
|
break; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
return $builder; |
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.