Completed
Push — develop ( a52dc0...a8f9d1 )
by Dieter
05:20
created

Base::createPNRRetrieve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
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\AirFlightInfoOptions;
28
use Amadeus\Client\RequestOptions\AirRetrieveSeatMapOptions;
29
use Amadeus\Client\RequestOptions\AirSellFromRecommendationOptions;
30
use Amadeus\Client\RequestOptions\CommandCrypticOptions;
31
use Amadeus\Client\RequestOptions\DocIssuanceIssueTicketOptions;
32
use Amadeus\Client\RequestOptions\FareCheckRulesOptions;
33
use Amadeus\Client\RequestOptions\FareConvertCurrencyOptions;
34
use Amadeus\Client\RequestOptions\FareInformativePricingWithoutPnrOptions;
35
use Amadeus\Client\RequestOptions\FareMasterPricerTbSearch;
36
use Amadeus\Client\RequestOptions\FarePricePnrWithBookingClassOptions;
37
use Amadeus\Client\RequestOptions\InfoEncodeDecodeCityOptions;
38
use Amadeus\Client\RequestOptions\MiniRuleGetFromPricingRecOptions;
39
use Amadeus\Client\RequestOptions\OfferConfirmAirOptions;
40
use Amadeus\Client\RequestOptions\OfferConfirmCarOptions;
41
use Amadeus\Client\RequestOptions\OfferConfirmHotelOptions;
42
use Amadeus\Client\RequestOptions\OfferVerifyOptions;
43
use Amadeus\Client\RequestOptions\Pnr\Element\ReceivedFrom;
44
use Amadeus\Client\RequestOptions\PnrAddMultiElementsBase;
45
use Amadeus\Client\RequestOptions\PnrAddMultiElementsOptions;
46
use Amadeus\Client\RequestOptions\PnrCancelOptions;
47
use Amadeus\Client\RequestOptions\PnrCreatePnrOptions;
48
use Amadeus\Client\RequestOptions\PnrDisplayHistoryOptions;
49
use Amadeus\Client\RequestOptions\PnrRetrieveAndDisplayOptions;
50
use Amadeus\Client\RequestOptions\PnrRetrieveOptions;
51
use Amadeus\Client\RequestOptions\PriceXplorerExtremeSearchOptions;
52
use Amadeus\Client\RequestOptions\QueueListOptions;
53
use Amadeus\Client\RequestOptions\QueueMoveItemOptions;
54
use Amadeus\Client\RequestOptions\QueuePlacePnrOptions;
55
use Amadeus\Client\RequestOptions\QueueRemoveItemOptions;
56
use Amadeus\Client\RequestOptions\RequestOptionsInterface;
57
use Amadeus\Client\RequestOptions\SecurityAuthenticateOptions;
58
use Amadeus\Client\RequestOptions\TicketCreateTstFromPricingOptions;
59
use Amadeus\Client\Struct;
60
61
/**
62
 * Base request creator - the default request creator.
63
 *
64
 * @package Amadeus\Client\RequestCreator
65
 * @author Dieter Devlieghere <[email protected]>
66
 */
67
class Base implements RequestCreatorInterface
68
{
69
    /**
70
     * @var RequestCreatorParams
71
     */
72
    protected $params;
73
74
    /**
75
     * Associative array of messages (as keys) and versions (as values) that are present in the WSDL.
76
     *
77
     * @var array
78
     */
79
    protected $messagesAndVersions = [];
80
81
    /**
82
     * @param $params
83
     */
84
    public function __construct(RequestCreatorParams $params)
85
    {
86
        $this->params = $params;
87
        $this->messagesAndVersions = $params->messagesAndVersions;
88
    }
89
90
    /**
91
     * @param string $messageName the message name as named in the WSDL
92
     * @param RequestOptionsInterface $params
93
     * @throws Struct\InvalidArgumentException When invalid input is detected during message creation.
94
     * @throws InvalidMessageException when trying to create a request for a message that is not in your WSDL.
95
     * @return mixed the created request
96
     */
97
    public function createRequest($messageName, RequestOptionsInterface $params)
98
    {
99
        $this->checkMessageIsInWsdl($messageName);
100
101
        $methodName = 'create' . str_replace("_", "", $messageName);
102
103
        if (method_exists($this, $methodName)) {
104
            return $this->$methodName($params);
105
        } else {
106
            throw new \RuntimeException('Message ' . $methodName . ' is not implemented in ' . __CLASS__);
107
        }
108
    }
109
110
    /**
111
     * @return Struct\Security\SignOut
112
     */
113
    protected function createSecuritySignOut()
114
    {
115
        return new Struct\Security\SignOut();
116
    }
117
118
    /**
119
     * Create request object for Security_Authenticate message
120
     *
121
     * @param SecurityAuthenticateOptions $params
122
     * @return Struct\Security\Authenticate
123
     */
124
    protected function createSecurityAuthenticate(SecurityAuthenticateOptions $params)
125
    {
126
        return new Struct\Security\Authenticate($params);
127
    }
128
129
    /**
130
     * Create request object for PNR_Retrieve message
131
     *
132
     * @param PnrRetrieveOptions $params
133
     * @return Struct\Pnr\Retrieve
134
     */
135
    protected function createPNRRetrieve(PnrRetrieveOptions $params)
136
    {
137
        $retrieveRequest = new Struct\Pnr\Retrieve(
138
            Struct\Pnr\Retrieve::RETR_TYPE_BY_RECLOC,
139
            $params->recordLocator
140
        );
141
142
        return $retrieveRequest;
143
    }
144
145
    /**
146
     * @param PnrRetrieveAndDisplayOptions $params
147
     * @return Struct\Pnr\RetrieveAndDisplay
148
     */
149
    protected function createPNRRetrieveAndDisplay(PnrRetrieveAndDisplayOptions $params)
150
    {
151
        $req = new Struct\Pnr\RetrieveAndDisplay(
152
            $params->recordLocator,
153
            $params->retrieveOption
154
        );
155
156
        return $req;
157
    }
158
159
    /**
160
     * @param PnrAddMultiElementsBase $params
161
     * @return Struct\Pnr\AddMultiElements
162
     */
163
    protected function createPNRAddMultiElements(PnrAddMultiElementsBase $params)
164
    {
165
        if ($params instanceof PnrCreatePnrOptions && empty($params->receivedFrom)) {
166
            //Automagically add RF if not present:
167
            $params->receivedFrom = $this->params->receivedFrom;
168
        }
169
170
        $req = new Struct\Pnr\AddMultiElements($params);
171
172
        return $req;
173
    }
174
175
    /**
176
     * @param PnrCancelOptions $params
177
     * @return Struct\Pnr\Cancel
178
     */
179
    protected function createPNRCancel(PnrCancelOptions $params)
180
    {
181
        return new Struct\Pnr\Cancel($params);
182
    }
183
184
    /**
185
     * @param PnrDisplayHistoryOptions $params
186
     * @return Struct\Pnr\Cancel
0 ignored issues
show
Documentation introduced by
Should the return type not be Struct\Pnr\DisplayHistory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
187
     */
188
    protected function createPNRDisplayHistory(PnrDisplayHistoryOptions $params)
189
    {
190
        return new Struct\Pnr\DisplayHistory($params);
191
    }
192
193
    /**
194
     * @param QueueListOptions $params
195
     * @return Struct\Queue\QueueList
196
     */
197
    protected function createQueueList(QueueListOptions $params)
198
    {
199
        $queueListRequest = new Struct\Queue\QueueList(
200
            $params->queue->queue,
201
            $params->queue->category
202
        );
203
204
        return $queueListRequest;
205
    }
206
207
    /**
208
     * @param QueuePlacePnrOptions $params
209
     * @return Struct\Queue\PlacePnr
210
     */
211
    protected function createQueuePlacePnr(QueuePlacePnrOptions $params)
212
    {
213
        $req = new Struct\Queue\PlacePnr(
214
            $params->recordLocator,
215
            $params->sourceOfficeId,
216
            $params->targetQueue
217
        );
218
219
        return $req;
220
    }
221
222
    /**
223
     * @param QueueRemoveItemOptions $params
224
     * @return Struct\Queue\RemoveItem
225
     */
226
    protected function createQueueRemoveItem(QueueRemoveItemOptions $params)
227
    {
228
        $req = new Struct\Queue\RemoveItem(
229
            $params->queue,
230
            $params->recordLocator,
231
            $params->originatorOfficeId
232
        );
233
234
        return $req;
235
    }
236
237
    /**
238
     * @param QueueMoveItemOptions $params
239
     * @return Struct\Queue\MoveItem
240
     */
241
    protected function createQueueMoveItem(QueueMoveItemOptions $params)
242
    {
243
        $req = new Struct\Queue\MoveItem(
244
            $params->recordLocator,
245
            $params->officeId,
246
            $params->sourceQueue,
247
            $params->destinationQueue
248
        );
249
250
        return $req;
251
    }
252
253
    /**
254
     * @param OfferVerifyOptions $params
255
     * @return Struct\Offer\Verify
256
     */
257
    protected function createOfferVerifyOffer(OfferVerifyOptions $params)
258
    {
259
        $req = new Struct\Offer\Verify(
260
            $params->offerReference,
261
            $params->segmentName
262
        );
263
264
        return $req;
265
    }
266
267
    /**
268
     * @param OfferConfirmAirOptions $params
269
     * @return Struct\Offer\ConfirmAir
270
     */
271
    protected function createOfferConfirmAirOffer(OfferConfirmAirOptions $params)
272
    {
273
        return new Struct\Offer\ConfirmAir($params);
274
    }
275
276
277
    /**
278
     * @param OfferConfirmHotelOptions $params
279
     * @return Struct\Offer\ConfirmHotel
280
     */
281
    protected function createOfferConfirmHotelOffer(OfferConfirmHotelOptions $params)
282
    {
283
        return new Struct\Offer\ConfirmHotel($params);
284
    }
285
286
    /**
287
     * @param OfferConfirmCarOptions $params
288
     * @return Struct\Offer\ConfirmCar
289
     */
290
    protected function createOfferConfirmCarOffer(OfferConfirmCarOptions $params)
291
    {
292
        return new Struct\Offer\ConfirmCar($params);
293
    }
294
295
    /**
296
     * createFareMasterPricerTravelBoardSearch
297
     *
298
     * @param FareMasterPricerTbSearch $params
299
     * @return Struct\Fare\MasterPricerTravelBoardSearch
300
     */
301
    protected function createFareMasterPricerTravelBoardSearch(FareMasterPricerTbSearch $params)
302
    {
303
        return new Struct\Fare\MasterPricerTravelBoardSearch($params);
304
    }
305
306
307
    /**
308
     * createFareCheckRules
309
     *
310
     * @param FareCheckRulesOptions $params
311
     * @return Struct\Fare\CheckRules
312
     */
313
    protected function createFareCheckRules(FareCheckRulesOptions $params)
314
    {
315
        return new Struct\Fare\CheckRules($params);
316
    }
317
318
    /**
319
     * createFareConvertCurrency
320
     *
321
     * @param FareConvertCurrencyOptions $params
322
     * @return Struct\Fare\ConvertCurrency
323
     */
324
    protected function createFareConvertCurrency(FareConvertCurrencyOptions $params)
325
    {
326
        return new Struct\Fare\ConvertCurrency($params);
327
    }
328
329
    /**
330
     * makeFarePricePnrWithBookingClass
331
     *
332
     * @param FarePricePnrWithBookingClassOptions $params
333
     * @return Struct\Fare\PricePNRWithBookingClass12|Struct\Fare\PricePNRWithBookingClass13
334
     */
335
    protected function createFarePricePnrWithBookingClass(FarePricePnrWithBookingClassOptions $params)
336
    {
337
        $version = $this->getActiveVersionFor('Fare_PricePNRWithBookingClass');
338
        if ($version < 13) {
339
            return new Struct\Fare\PricePNRWithBookingClass12($params);
340
        } else {
341
            return new Struct\Fare\PricePNRWithBookingClass13($params);
342
        }
343
    }
344
345
    /**
346
     * createFareInformativePricingWithoutPNR
347
     *
348
     * @param FareInformativePricingWithoutPnrOptions $params
349
     * @return Struct\Fare\InformativePricingWithoutPNR12|Struct\Fare\InformativePricingWithoutPNR13
350
     */
351
    protected function createFareInformativePricingWithoutPNR(FareInformativePricingWithoutPnrOptions $params)
352
    {
353
        $version = $this->getActiveVersionFor('Fare_InformativePricingWithoutPNR');
354
        if ($version < 13) {
355
            return new Struct\Fare\InformativePricingWithoutPNR12($params);
356
        } else {
357
            return new Struct\Fare\InformativePricingWithoutPNR13($params);
358
        }
359
    }
360
361
    /**
362
     *
363
     * @param AirSellFromRecommendationOptions $params
364
     * @return Struct\Air\SellFromRecommendation
365
     */
366
    protected function createAirSellFromRecommendation(AirSellFromRecommendationOptions $params)
367
    {
368
        return new Struct\Air\SellFromRecommendation($params);
369
    }
370
371
    /**
372
     *
373
     * @param AirFlightInfoOptions $params
374
     * @return Struct\Air\FlightInfo
375
     */
376
    protected function createAirFlightInfo(AirFlightInfoOptions $params)
377
    {
378
        return new Struct\Air\FlightInfo($params);
379
    }
380
381
    /**
382
     * @param AirRetrieveSeatMapOptions $params
383
     * @return Struct\Air\RetrieveSeatMap
384
     */
385
    protected function createAirRetrieveSeatMap(AirRetrieveSeatMapOptions $params)
386
    {
387
        return new Struct\Air\RetrieveSeatMap($params);
388
    }
389
390
    /**
391
     * makeCommandCryptic
392
     *
393
     * @param CommandCrypticOptions $params
394
     * @return Struct\Command\Cryptic
395
     */
396
    protected function createCommandCryptic(CommandCrypticOptions $params)
397
    {
398
        return new Struct\Command\Cryptic($params->entry);
399
    }
400
401
    /**
402
     * Info_EncodeDecodeCity
403
     *
404
     * @param InfoEncodeDecodeCityOptions $params
405
     * @return Struct\Info\EncodeDecodeCity
406
     */
407
    protected function createInfoEncodeDecodeCity(InfoEncodeDecodeCityOptions $params)
408
    {
409
        return new Struct\Info\EncodeDecodeCity($params);
410
    }
411
412
    /**
413
     * makeMiniRuleGetFromPricingRec
414
     *
415
     * @param MiniRuleGetFromPricingRecOptions $params
416
     * @return Struct\MiniRule\GetFromPricingRec
417
     */
418
    protected function createMiniRuleGetFromPricingRec(MiniRuleGetFromPricingRecOptions $params)
419
    {
420
        return new Struct\MiniRule\GetFromPricingRec($params);
421
    }
422
423
    /**
424
     * Ticket_CreateTstFromPricing
425
     *
426
     * @param TicketCreateTstFromPricingOptions $params
427
     * @return Struct\Ticket\CreateTSTFromPricing
428
     */
429
    protected function createTicketCreateTSTFromPricing(TicketCreateTstFromPricingOptions $params)
430
    {
431
        return new Struct\Ticket\CreateTSTFromPricing($params);
432
    }
433
434
    /**
435
     * DocIssuance_IssueTicket
436
     *
437
     * @param DocIssuanceIssueTicketOptions $params
438
     * @return Struct\DocIssuance\IssueTicket
439
     */
440
    protected function createDocIssuanceIssueTicket(DocIssuanceIssueTicketOptions $params)
441
    {
442
        return new Struct\DocIssuance\IssueTicket($params);
443
    }
444
445
    /**
446
     * PriceXplorer_ExtremeSearch
447
     *
448
     * @param PriceXplorerExtremeSearchOptions $params
449
     * @return Struct\PriceXplorer\ExtremeSearch
450
     */
451
    protected function createPriceXplorerExtremeSearch(PriceXplorerExtremeSearchOptions $params)
452
    {
453
        return new Struct\PriceXplorer\ExtremeSearch($params);
454
    }
455
456
    /**
457
     * Check if a given message is in the active WSDL. Throws exception if it isn't.
458
     *
459
     * @throws InvalidMessageException if message is not in WSDL.
460
     * @param string $messageName
461
     */
462
    protected function checkMessageIsInWsdl($messageName)
463
    {
464
        if (!array_key_exists($messageName, $this->messagesAndVersions)) {
465
            throw new InvalidMessageException('Message "' . $messageName . '" is not in WDSL');
466
        }
467
    }
468
469
    /**
470
     * Get the version number active in the WSDL for the given message
471
     *
472
     * @param $messageName
473
     * @return float|string
474
     */
475
    protected function getActiveVersionFor($messageName)
476
    {
477
        return $this->messagesAndVersions[$messageName];
478
    }
479
}
480