Completed
Push — master ( 5242c7...dcb951 )
by Dieter
07:52
created

Client::offerCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
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;
24
25
use Amadeus\Client\Exception;
26
use Amadeus\Client\Params;
27
use Amadeus\Client\RequestCreator\RequestCreatorInterface;
28
use Amadeus\Client\RequestOptions;
29
use Amadeus\Client\ResponseHandler\ResponseHandlerInterface;
30
use Amadeus\Client\Result;
31
use Amadeus\Client\Session\Handler\HandlerFactory;
32
use Amadeus\Client\RequestCreator\Factory as RequestCreatorFactory;
33
use Amadeus\Client\Session\Handler\HandlerInterface;
34
use Amadeus\Client\ResponseHandler\Base as ResponseHandlerBase;
35
36
/**
37
 * Amadeus Web Service Client.
38
 *
39
 * TODO:
40
 * - support older versions of SoapHeader (1)
41
 *
42
 * @package Amadeus
43
 * @author Dieter Devlieghere <[email protected]>
44
 */
45
class Client
46
{
47
    /**
48
     * Amadeus SOAP header version 1
49
     */
50
    const HEADER_V1 = "1";
51
    /**
52
     * Amadeus SOAP header version 2
53
     */
54
    const HEADER_V2 = "2";
55
    /**
56
     * Amadeus SOAP header version 4
57
     */
58
    const HEADER_V4 = "4";
59
60
    /**
61
     * Version string
62
     *
63
     * @var string
64
     */
65
    const VERSION = "1.1.0-dev";
66
67
    /**
68
     * An identifier string for the library (to be used in Received From entries)
69
     *
70
     * @var string
71
     */
72
    const RECEIVED_FROM_IDENTIFIER = "amabnl-amadeus-ws-client";
73
74
    /**
75
     * Session Handler will be sending all the messages and handling all session-related things.
76
     *
77
     * @var HandlerInterface
78
     */
79
    protected $sessionHandler;
80
81
    /**
82
     * Request Creator is will create the correct message structure to send to the SOAP server.
83
     *
84
     * @var RequestCreatorInterface
85
     */
86
    protected $requestCreator;
87
88
    /**
89
     * Response Handler will check the received response for errors.
90
     *
91
     * @var ResponseHandlerInterface
92
     */
93
    protected $responseHandler;
94
95
    /**
96
     * Authentication parameters
97
     *
98
     * @var Params\AuthParams
99
     */
100
    protected $authParams;
101
102
    /**
103
     * @var string
104
     */
105
    protected $lastMessage;
106
107
    /**
108
     * Set the session as stateful (true) or stateless (false)
109
     *
110
     * @param bool $newStateful
111
     */
112
    public function setStateful($newStateful)
113
    {
114
        $this->sessionHandler->setStateful($newStateful);
115
    }
116
117
    /**
118
     * @return bool
119
     */
120
    public function isStateful()
121
    {
122
        return $this->sessionHandler->isStateful();
123
    }
124
125
    /**
126
     * Get the last raw XML message that was sent out
127
     *
128
     * @return string|null
129
     */
130
    public function getLastRequest()
131
    {
132
        return $this->sessionHandler->getLastRequest($this->lastMessage);
133
    }
134
135
    /**
136
     * Get the last raw XML message that was received
137
     *
138
     * @return string|null
139
     */
140
    public function getLastResponse()
141
    {
142
        return $this->sessionHandler->getLastResponse($this->lastMessage);
143
    }
144
145
    /**
146
     * Get session information for authenticated session
147
     *
148
     * - sessionId
149
     * - sequenceNr
150
     * - securityToken
151
     *
152
     * @return array|null
153
     */
154
    public function getSessionData()
155
    {
156
        return $this->sessionHandler->getSessionData();
157
    }
158
159
    /**
160
     * Restore a previously used session
161
     *
162
     * To be used when implementing your own session pooling system on legacy Soap Header 2 applications.
163
     *
164
     * @param array $sessionData
165
     * @return bool
166
     */
167
    public function setSessionData(array $sessionData)
168
    {
169
        return $this->sessionHandler->setSessionData($sessionData);
170
    }
171
172
    /**
173
     * Construct Amadeus Web Services client
174
     *
175
     * @param Params $params
176
     */
177
    public function __construct($params)
178
    {
179
        if ($params->authParams instanceof Params\AuthParams) {
180
            $this->authParams = $params->authParams;
181
            if (isset($params->sessionHandlerParams) &&
182
                $params->sessionHandlerParams instanceof Params\SessionHandlerParams
183
            ) {
184
                $params->sessionHandlerParams->authParams = $this->authParams;
185
            }
186
        }
187
188
        $this->sessionHandler = $this->loadSessionHandler(
189
            $params->sessionHandler,
190
            $params->sessionHandlerParams
191
        );
192
193
        $this->requestCreator = $this->loadRequestCreator(
194
            $params->requestCreator,
195
            $params->requestCreatorParams,
196
            self::RECEIVED_FROM_IDENTIFIER . "-" .self::VERSION,
197
            $this->sessionHandler->getOriginatorOffice(),
198
            $this->sessionHandler->getMessagesAndVersions()
199
        );
200
201
        $this->responseHandler = $this->loadResponseHandler(
202
            $params->responseHandler
203
        );
204
    }
205
206
    /**
207
     * Authenticate.
208
     *
209
     * Parameters were provided at construction time (sessionhandlerparams)
210
     *
211
     * @return Result
212
     * @throws Exception
213
     */
214
    public function securityAuthenticate()
215
    {
216
        $msgName = 'Security_Authenticate';
217
218
        return $this->callMessage(
219
            $msgName,
220
            new RequestOptions\SecurityAuthenticateOptions(
221
                $this->authParams
222
            ),
223
            [],
224
            false
225
        );
226
    }
227
228
    /**
229
     * Terminate a session - only applicable to non-stateless mode.
230
     *
231
     * @return Result
232
     * @throws Exception
233
     */
234
    public function securitySignOut()
235
    {
236
        $msgName = 'Security_SignOut';
237
238
        return $this->callMessage(
239
            $msgName,
240
            new RequestOptions\SecuritySignOutOptions(),
241
            [],
242
            true
243
        );
244
    }
245
246
    /**
247
     * PNR_Retrieve - Retrieve an Amadeus PNR by record locator
248
     *
249
     * By default, the result will be the PNR_Reply XML as string.
250
     * That way you can easily parse the PNR's contents with XPath.
251
     *
252
     * https://webservices.amadeus.com/extranet/viewService.do?id=27&flavourId=1&menuId=functional
253
     *
254
     * @param RequestOptions\PnrRetrieveOptions $options
255
     * @param array $messageOptions (OPTIONAL)
256
     * @return Result
257
     * @throws Exception
258
     */
259
    public function pnrRetrieve(RequestOptions\PnrRetrieveOptions $options, $messageOptions = [])
260
    {
261
        $msgName = 'PNR_Retrieve';
262
263
        return $this->callMessage($msgName, $options, $messageOptions);
264
    }
265
266
    /**
267
     * Create a PNR using PNR_AddMultiElements
268
     *
269
     * @param RequestOptions\PnrCreatePnrOptions $options
270
     * @param array $messageOptions (OPTIONAL)
271
     * @return Result
272
     */
273
    public function pnrCreatePnr(RequestOptions\PnrCreatePnrOptions $options, $messageOptions = [])
274
    {
275
        $msgName = 'PNR_AddMultiElements';
276
277
        return $this->callMessage($msgName, $options, $messageOptions);
278
    }
279
280
    /**
281
     * PNR_AddMultiElements - Create a new PNR or update an existing PNR.
282
     *
283
     * https://webservices.amadeus.com/extranet/viewService.do?id=25&flavourId=1&menuId=functional
284
     *
285
     * @param RequestOptions\PnrAddMultiElementsOptions $options
286
     * @param array $messageOptions (OPTIONAL)
287
     * @return Result
288
     */
289
    public function pnrAddMultiElements(RequestOptions\PnrAddMultiElementsOptions $options, $messageOptions = [])
290
    {
291
        $msgName = 'PNR_AddMultiElements';
292
293
        return $this->callMessage($msgName, $options, $messageOptions);
294
    }
295
296
    /**
297
     * PNR_RetrieveAndDisplay - Retrieve an Amadeus PNR by record locator including extra info
298
     *
299
     * This extra info is info you cannot see in the regular PNR, like Offers.
300
     *
301
     * By default, the result will be the PNR_RetrieveAndDisplayReply XML as string.
302
     * That way you can easily parse the PNR's contents with XPath.
303
     *
304
     * Set $messageOptions['asString'] = FALSE to get the response as a PHP object.
305
     *
306
     * https://webservices.amadeus.com/extranet/viewService.do?id=1922&flavourId=1&menuId=functional
307
     *
308
     * @param RequestOptions\PnrRetrieveAndDisplayOptions $options Amadeus Record Locator for PNR
309
     * @param array $messageOptions (OPTIONAL)
310
     * @return Result
311
     * @throws Exception
312
     **/
313
    public function pnrRetrieveAndDisplay(RequestOptions\PnrRetrieveAndDisplayOptions $options, $messageOptions = [])
314
    {
315
        $msgName = 'PNR_RetrieveAndDisplay';
316
317
        return $this->callMessage($msgName, $options, $messageOptions);
318
    }
319
320
    /**
321
     * PNR_Cancel
322
     *
323
     * @param RequestOptions\PnrCancelOptions $options
324
     * @param array $messageOptions (OPTIONAL)
325
     * @return Result
326
     */
327
    public function pnrCancel(RequestOptions\PnrCancelOptions $options, $messageOptions = [])
328
    {
329
        $msgName = 'PNR_Cancel';
330
331
        return $this->callMessage($msgName, $options, $messageOptions);
332
    }
333
334
    /**
335
     * PNR_DisplayHistory
336
     *
337
     * @param RequestOptions\PnrDisplayHistoryOptions $options
338
     * @param array $messageOptions (OPTIONAL)
339
     * @return Result
340
     */
341
    public function pnrDisplayHistory(RequestOptions\PnrDisplayHistoryOptions $options, $messageOptions = [])
342
    {
343
        $msgName = 'PNR_DisplayHistory';
344
345
        return $this->callMessage($msgName, $options, $messageOptions);
346
    }
347
348
    /**
349
     * PNR_TransferOwnership
350
     *
351
     * @param RequestOptions\PnrTransferOwnershipOptions $options
352
     * @param array $messageOptions (OPTIONAL)
353
     * @return Result
354
     */
355
    public function pnrTransferOwnership(RequestOptions\PnrTransferOwnershipOptions $options, $messageOptions = [])
356
    {
357
        $msgName = 'PNR_TransferOwnership';
358
359
        return $this->callMessage($msgName, $options, $messageOptions);
360
    }
361
362
    /**
363
     * Queue_List - get a list of all PNR's on a given queue
364
     *
365
     * https://webservices.amadeus.com/extranet/viewService.do?id=52&flavourId=1&menuId=functional
366
     *
367
     * @param RequestOptions\QueueListOptions $options
368
     * @param array $messageOptions (OPTIONAL)
369
     * @return Result
370
     */
371
    public function queueList(RequestOptions\QueueListOptions $options, $messageOptions = [])
372
    {
373
        $msgName = 'Queue_List';
374
375
        return $this->callMessage($msgName, $options, $messageOptions);
376
    }
377
378
    /**
379
     * Queue_PlacePNR - Place a PNR on a given queue
380
     *
381
     * @param RequestOptions\QueuePlacePnrOptions $options
382
     * @param array $messageOptions (OPTIONAL)
383
     * @return Result
384
     */
385
    public function queuePlacePnr(RequestOptions\QueuePlacePnrOptions $options, $messageOptions = [])
386
    {
387
        $msgName = 'Queue_PlacePNR';
388
389
        return $this->callMessage($msgName, $options, $messageOptions);
390
    }
391
392
    /**
393
     * Queue_RemoveItem - remove an item (a PNR) from a given queue
394
     *
395
     * @param RequestOptions\QueueRemoveItemOptions $options
396
     * @param array $messageOptions (OPTIONAL)
397
     * @return Result
398
     */
399
    public function queueRemoveItem(RequestOptions\QueueRemoveItemOptions $options, $messageOptions = [])
400
    {
401
        $msgName = 'Queue_RemoveItem';
402
403
        return $this->callMessage($msgName, $options, $messageOptions);
404
    }
405
406
    /**
407
     * Queue_MoveItem - move an item (a PNR) from one queue to another.
408
     *
409
     * @param RequestOptions\QueueMoveItemOptions $options
410
     * @param array $messageOptions (OPTIONAL)
411
     * @return Result
412
     */
413
    public function queueMoveItem(RequestOptions\QueueMoveItemOptions $options, $messageOptions = [])
414
    {
415
        $msgName = 'Queue_MoveItem';
416
417
        return $this->callMessage($msgName, $options, $messageOptions);
418
    }
419
420
    /**
421
     * Offer_CreateOffer
422
     *
423
     * @param RequestOptions\OfferCreateOptions $options
424
     * @param array $messageOptions (OPTIONAL)
425
     * @return Result
426
     */
427
    public function offerCreate(RequestOptions\OfferCreateOptions $options, $messageOptions = [])
428
    {
429
        $msgName = 'Offer_CreateOffer';
430
431
        return $this->callMessage($msgName, $options, $messageOptions);
432
    }
433
434
    /**
435
     * Offer_VerifyOffer
436
     *
437
     * To be called in the context of an open PNR
438
     *
439
     * @param RequestOptions\OfferVerifyOptions $options
440
     * @param array $messageOptions (OPTIONAL)
441
     * @return Result
442
     */
443
    public function offerVerify(RequestOptions\OfferVerifyOptions $options, $messageOptions = [])
444
    {
445
        $msgName = 'Offer_VerifyOffer';
446
447
        return $this->callMessage($msgName, $options, $messageOptions);
448
    }
449
450
    /**
451
     * Offer_ConfirmAirOffer
452
     *
453
     * @param RequestOptions\OfferConfirmAirOptions $options
454
     * @param array $messageOptions (OPTIONAL)
455
     * @return Result
456
     */
457
    public function offerConfirmAir(RequestOptions\OfferConfirmAirOptions $options, $messageOptions = [])
458
    {
459
        $msgName = 'Offer_ConfirmAirOffer';
460
461
        return $this->callMessage($msgName, $options, $messageOptions);
462
    }
463
464
    /**
465
     * Offer_ConfirmHotelOffer
466
     *
467
     * @param RequestOptions\OfferConfirmHotelOptions $options
468
     * @param array $messageOptions (OPTIONAL)
469
     * @return Result
470
     */
471
    public function offerConfirmHotel(RequestOptions\OfferConfirmHotelOptions $options, $messageOptions = [])
472
    {
473
        $msgName = 'Offer_ConfirmHotelOffer';
474
475
        return $this->callMessage($msgName, $options, $messageOptions);
476
    }
477
478
    /**
479
     * Offer_ConfirmCarOffer
480
     *
481
     * @param RequestOptions\OfferConfirmCarOptions $options
482
     * @param array $messageOptions (OPTIONAL)
483
     * @return Result
484
     */
485
    public function offerConfirmCar(RequestOptions\OfferConfirmCarOptions $options, $messageOptions = [])
486
    {
487
        $msgName = 'Offer_ConfirmCarOffer';
488
489
        return $this->callMessage($msgName, $options, $messageOptions);
490
    }
491
492
    /**
493
     * Fare_MasterPricerTravelBoardSearch
494
     *
495
     * @param RequestOptions\FareMasterPricerTbSearch $options
496
     * @param array $messageOptions (OPTIONAL)
497
     * @return Result
498
     */
499
    public function fareMasterPricerTravelBoardSearch(
500
        RequestOptions\FareMasterPricerTbSearch $options,
501
        $messageOptions = []
502
    ) {
503
        $msgName = 'Fare_MasterPricerTravelBoardSearch';
504
505
        return $this->callMessage($msgName, $options, $messageOptions);
506
    }
507
508
    /**
509
     * Fare_MasterPricerCalendar
510
     *
511
     * @param RequestOptions\FareMasterPricerCalendarOptions $options
512
     * @param array $messageOptions (OPTIONAL)
513
     * @return Result
514
     */
515
    public function fareMasterPricerCalendar(
516
        RequestOptions\FareMasterPricerCalendarOptions $options,
517
        $messageOptions = []
518
    ) {
519
        $msgName = 'Fare_MasterPricerCalendar';
520
521
        return $this->callMessage($msgName, $options, $messageOptions);
522
    }
523
524
    /**
525
     * Fare_PricePnrWithBookingClass
526
     *
527
     * @param RequestOptions\FarePricePnrWithBookingClassOptions $options
528
     * @param array $messageOptions (OPTIONAL)
529
     * @return Result
530
     */
531
    public function farePricePnrWithBookingClass(
532
        RequestOptions\FarePricePnrWithBookingClassOptions $options,
533
        $messageOptions = []
534
    ) {
535
        $msgName = 'Fare_PricePNRWithBookingClass';
536
537
        return $this->callMessage($msgName, $options, $messageOptions);
538
    }
539
540
    /**
541
     * Fare_PricePnrWithLowerFares
542
     *
543
     * @param RequestOptions\FarePricePnrWithLowerFaresOptions $options
544
     * @param array $messageOptions (OPTIONAL)
545
     * @return Result
546
     */
547
    public function farePricePnrWithLowerFares(
548
        RequestOptions\FarePricePnrWithLowerFaresOptions $options,
549
        $messageOptions = []
550
    ) {
551
        $msgName = 'Fare_PricePNRWithLowerFares';
552
553
        return $this->callMessage($msgName, $options, $messageOptions);
554
    }
555
556
    /**
557
     * Fare_PricePnrWithLowestFare
558
     *
559
     * @param RequestOptions\FarePricePnrWithLowestFareOptions $options
560
     * @param array $messageOptions (OPTIONAL)
561
     * @return Result
562
     */
563
    public function farePricePnrWithLowestFare(
564
        RequestOptions\FarePricePnrWithLowestFareOptions $options,
565
        $messageOptions = []
566
    ) {
567
        $msgName = 'Fare_PricePNRWithLowestFare';
568
569
        return $this->callMessage($msgName, $options, $messageOptions);
570
    }
571
572
    /**
573
     * Fare_InformativePricingWithoutPNR
574
     *
575
     * @param RequestOptions\FareInformativePricingWithoutPnrOptions $options
576
     * @param array $messageOptions (OPTIONAL)
577
     * @return Result
578
     */
579
    public function fareInformativePricingWithoutPnr(
580
        RequestOptions\FareInformativePricingWithoutPnrOptions $options,
581
        $messageOptions = []
582
    ) {
583
        $msgName = 'Fare_InformativePricingWithoutPNR';
584
585
        return $this->callMessage($msgName, $options, $messageOptions);
586
    }
587
588
    /**
589
     * Fare_InformativeBestPricingWithoutPNR
590
     *
591
     * @param RequestOptions\FareInformativeBestPricingWithoutPnrOptions $options
592
     * @param array $messageOptions (OPTIONAL)
593
     * @return Result
594
     */
595
    public function fareInformativeBestPricingWithoutPnr(
596
        RequestOptions\FareInformativeBestPricingWithoutPnrOptions $options,
597
        $messageOptions = []
598
    ) {
599
        $msgName = 'Fare_InformativeBestPricingWithoutPNR';
600
601
        return $this->callMessage($msgName, $options, $messageOptions);
602
    }
603
604
    /**
605
     * Fare_CheckRules
606
     *
607
     * @param RequestOptions\FareCheckRulesOptions $options
608
     * @param array $messageOptions (OPTIONAL)
609
     * @return Result
610
     */
611
    public function fareCheckRules(RequestOptions\FareCheckRulesOptions $options, $messageOptions = [])
612
    {
613
        $msgName = 'Fare_CheckRules';
614
615
        return $this->callMessage($msgName, $options, $messageOptions);
616
    }
617
618
    /**
619
     * Fare_ConvertCurrency
620
     *
621
     * @param RequestOptions\FareConvertCurrencyOptions $options
622
     * @param array $messageOptions (OPTIONAL)
623
     * @return Result
624
     */
625
    public function fareConvertCurrency(RequestOptions\FareConvertCurrencyOptions $options, $messageOptions = [])
626
    {
627
        $msgName = 'Fare_ConvertCurrency';
628
629
        return $this->callMessage($msgName, $options, $messageOptions);
630
    }
631
632
    /**
633
     * Air_MultiAvailability
634
     *
635
     * @param RequestOptions\AirMultiAvailabilityOptions $options
636
     * @param array $messageOptions (OPTIONAL)
637
     * @return Result
638
     */
639
    public function airMultiAvailability(
640
        RequestOptions\AirMultiAvailabilityOptions $options,
641
        $messageOptions = []
642
    ) {
643
        $msgName = 'Air_MultiAvailability';
644
645
        return $this->callMessage($msgName, $options, $messageOptions);
646
    }
647
648
    /**
649
     * Air_SellFromRecommendation
650
     *
651
     * @param RequestOptions\AirSellFromRecommendationOptions $options
652
     * @param array $messageOptions (OPTIONAL)
653
     * @return Result
654
     */
655
    public function airSellFromRecommendation(
656
        RequestOptions\AirSellFromRecommendationOptions $options,
657
        $messageOptions = []
658
    ) {
659
        $msgName = 'Air_SellFromRecommendation';
660
661
        return $this->callMessage($msgName, $options, $messageOptions);
662
    }
663
664
    /**
665
     * Air_FlightInfo
666
     *
667
     * @param RequestOptions\AirFlightInfoOptions $options
668
     * @param array $messageOptions (OPTIONAL)
669
     * @return Result
670
     */
671
    public function airFlightInfo(RequestOptions\AirFlightInfoOptions $options, $messageOptions = [])
672
    {
673
        $msgName = 'Air_FlightInfo';
674
675
        return $this->callMessage($msgName, $options, $messageOptions);
676
    }
677
678
    /**
679
     * Air_RetrieveSeatMap
680
     *
681
     * @param RequestOptions\AirRetrieveSeatMapOptions $options
682
     * @param array $messageOptions (OPTIONAL)
683
     * @return Result
684
     */
685
    public function airRetrieveSeatMap(RequestOptions\AirRetrieveSeatMapOptions $options, $messageOptions = [])
686
    {
687
        $msgName = 'Air_RetrieveSeatMap';
688
689
        return $this->callMessage($msgName, $options, $messageOptions);
690
    }
691
692
    /**
693
     * Command_Cryptic
694
     *
695
     * @param RequestOptions\CommandCrypticOptions $options
696
     * @param array $messageOptions (OPTIONAL)
697
     * @return Result
698
     */
699
    public function commandCryptic(RequestOptions\CommandCrypticOptions $options, $messageOptions = [])
700
    {
701
        $msgName = 'Command_Cryptic';
702
703
        return $this->callMessage($msgName, $options, $messageOptions);
704
    }
705
706
    /**
707
     * MiniRule_GetFromPricingRec
708
     *
709
     * @param RequestOptions\MiniRuleGetFromPricingRecOptions $options
710
     * @param array $messageOptions (OPTIONAL)
711
     * @return Result
712
     */
713
    public function miniRuleGetFromPricingRec(
714
        RequestOptions\MiniRuleGetFromPricingRecOptions $options,
715
        $messageOptions = []
716
    ) {
717
        $msgName = 'MiniRule_GetFromPricingRec';
718
719
        return $this->callMessage($msgName, $options, $messageOptions);
720
    }
721
722
    /**
723
     * MiniRule_GetFromPricing
724
     *
725
     * @param RequestOptions\MiniRuleGetFromPricingOptions $options
726
     * @param array $messageOptions (OPTIONAL)
727
     * @return Result
728
     */
729
    public function miniRuleGetFromPricing(
730
        RequestOptions\MiniRuleGetFromPricingOptions $options,
731
        $messageOptions = []
732
    ) {
733
        $msgName = 'MiniRule_GetFromPricing';
734
735
        return $this->callMessage($msgName, $options, $messageOptions);
736
    }
737
738
    /**
739
     * Info_EncodeDecodeCity
740
     *
741
     * @param RequestOptions\InfoEncodeDecodeCityOptions $options
742
     * @param array $messageOptions (OPTIONAL)
743
     * @return Result
744
     */
745
    public function infoEncodeDecodeCity(RequestOptions\InfoEncodeDecodeCityOptions $options, $messageOptions = [])
746
    {
747
        $msgName = 'Info_EncodeDecodeCity';
748
749
        return $this->callMessage($msgName, $options, $messageOptions);
750
    }
751
752
753
    /**
754
     * Ticket_CreateTSTFromPricing
755
     *
756
     * @param RequestOptions\TicketCreateTstFromPricingOptions $options
757
     * @param array $messageOptions (OPTIONAL)
758
     * @return Result
759
     */
760
    public function ticketCreateTSTFromPricing(
761
        RequestOptions\TicketCreateTstFromPricingOptions $options,
762
        $messageOptions = []
763
    ) {
764
        $msgName = 'Ticket_CreateTSTFromPricing';
765
766
        return $this->callMessage($msgName, $options, $messageOptions);
767
    }
768
769
    /**
770
     * Ticket_DeleteTST
771
     *
772
     * @param RequestOptions\TicketDeleteTstOptions $options
773
     * @param array $messageOptions (OPTIONAL)
774
     * @return Result
775
     */
776
    public function ticketDeleteTST(RequestOptions\TicketDeleteTstOptions $options, $messageOptions = [])
777
    {
778
        $msgName = 'Ticket_DeleteTST';
779
780
        return $this->callMessage($msgName, $options, $messageOptions);
781
    }
782
783
    /**
784
     * Ticket_DisplayTST
785
     *
786
     * @param RequestOptions\TicketDisplayTstOptions $options
787
     * @param array $messageOptions (OPTIONAL)
788
     * @return Result
789
     */
790
    public function ticketDisplayTST(RequestOptions\TicketDisplayTstOptions $options, $messageOptions = [])
791
    {
792
        $msgName = 'Ticket_DisplayTST';
793
794
        return $this->callMessage($msgName, $options, $messageOptions);
795
    }
796
797
    /**
798
     * DocIssuance_IssueTicket
799
     *
800
     * @param RequestOptions\DocIssuanceIssueTicketOptions $options
801
     * @param array $messageOptions (OPTIONAL)
802
     * @return Result
803
     */
804
    public function docIssuanceIssueTicket(
805
        RequestOptions\DocIssuanceIssueTicketOptions $options,
806
        $messageOptions = []
807
    ) {
808
        $msgName = 'DocIssuance_IssueTicket';
809
810
        return $this->callMessage($msgName, $options, $messageOptions);
811
    }
812
813
    /**
814
     * PriceXplorer_ExtremeSearch
815
     *
816
     * @param RequestOptions\PriceXplorerExtremeSearchOptions $options
817
     * @param array $messageOptions (OPTIONAL)
818
     * @return Result
819
     */
820
    public function priceXplorerExtremeSearch(
821
        RequestOptions\PriceXplorerExtremeSearchOptions $options,
822
        $messageOptions = []
823
    ) {
824
        $msgName = 'PriceXplorer_ExtremeSearch';
825
826
        return $this->callMessage($msgName, $options, $messageOptions);
827
    }
828
829
    /**
830
     * SalesReports_DisplayQueryReport
831
     *
832
     * @param RequestOptions\SalesReportsDisplayQueryReportOptions $options
833
     * @param array $messageOptions (OPTIONAL)
834
     * @return Result
835
     */
836
    public function salesReportsDisplayQueryReport(
837
        RequestOptions\SalesReportsDisplayQueryReportOptions $options,
838
        $messageOptions = []
839
    ) {
840
        $msgName = 'SalesReports_DisplayQueryReport';
841
842
        return $this->callMessage($msgName, $options, $messageOptions);
843
    }
844
845
    /**
846
     * Call a message with the given parameters
847
     *
848
     * @param string $messageName
849
     * @param RequestOptions\RequestOptionsInterface $options
850
     * @param array $messageOptions
851
     * @param bool $endSession
852
     * @return Result
853
     * @throws Client\Exception
854
     * @throws Client\Struct\InvalidArgumentException
855
     * @throws Client\InvalidMessageException
856
     * @throws Client\RequestCreator\MessageVersionUnsupportedException
857
     * @throws \RuntimeException
858
     * @throws \InvalidArgumentException
859
     * @throws \SoapFault
860
     */
861
    protected function callMessage($messageName, $options, $messageOptions, $endSession = false)
862
    {
863
        $messageOptions = $this->makeMessageOptions($messageOptions, $endSession);
864
865
        $this->lastMessage = $messageName;
866
867
        $sendResult = $this->sessionHandler->sendMessage(
868
            $messageName,
869
            $this->requestCreator->createRequest(
870
                $messageName,
871
                $options
872
            ),
873
            $messageOptions
874
        );
875
876
        return $this->responseHandler->analyzeResponse(
877
            $sendResult,
878
            $messageName
879
        );
880
    }
881
882
    /**
883
     * Make message options
884
     *
885
     * Message options are meta options when sending a message to the amadeus web services
886
     * - (if stateful) should we end the current session after sending this call?
887
     * - ... ?
888
     *
889
     * @param array $incoming The Message options chosen by the caller - if any.
890
     * @param bool $endSession Switch if you want to terminate the current session after making the call.
891
     * @return array
892
     */
893
    protected function makeMessageOptions(array $incoming, $endSession = false)
894
    {
895
        $options = [
896
            'endSession' => $endSession
897
        ];
898
899
        if (array_key_exists('endSession', $incoming)) {
900
            $options['endSession'] = $incoming['endSession'];
901
        }
902
903
        return $options;
904
    }
905
906
    /**
907
     * Load the session handler
908
     *
909
     * Either load the provided session handler or create one depending on incoming parameters.
910
     *
911
     * @param HandlerInterface|null $sessionHandler
912
     * @param Params\SessionHandlerParams|null $params
913
     * @return HandlerInterface
914
     */
915
    protected function loadSessionHandler($sessionHandler, $params)
916
    {
917
        $newSessionHandler = null;
0 ignored issues
show
Unused Code introduced by
$newSessionHandler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
918
919
        if ($sessionHandler instanceof HandlerInterface) {
920
            $newSessionHandler = $sessionHandler;
921
        } else {
922
            $newSessionHandler = HandlerFactory::createHandler($params);
923
        }
924
925
        return $newSessionHandler;
926
    }
927
928
    /**
929
     * Load a request creator
930
     *
931
     * A request creator is responsible for generating the correct request to send.
932
     *
933
     * @param RequestCreatorInterface|null $requestCreator
934
     * @param Params\RequestCreatorParams $params
935
     * @param string $libIdentifier Library identifier & version string (for Received From)
936
     * @param string $originatorOffice The Office we are signed in with.
937
     * @param array $mesVer Messages & Versions array of active messages in the WSDL
938
     * @return RequestCreatorInterface
939
     * @throws \RuntimeException
940
     */
941
    protected function loadRequestCreator($requestCreator, $params, $libIdentifier, $originatorOffice, $mesVer)
942
    {
943
        $newRequestCreator = null;
0 ignored issues
show
Unused Code introduced by
$newRequestCreator is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
944
945
        if ($requestCreator instanceof RequestCreatorInterface) {
946
            $newRequestCreator = $requestCreator;
947
        } else {
948
            $params->originatorOfficeId = $originatorOffice;
949
            $params->messagesAndVersions = $mesVer;
950
951
            $newRequestCreator = RequestCreatorFactory::createRequestCreator(
952
                $params,
953
                $libIdentifier
954
            );
955
        }
956
957
        return $newRequestCreator;
958
    }
959
960
    /**
961
     * Load a response handler
962
     *
963
     * @param ResponseHandlerInterface|null $responseHandler
964
     *
965
     * @return ResponseHandlerInterface
966
     * @throws \RuntimeException
967
     */
968
    protected function loadResponseHandler($responseHandler)
969
    {
970
        $newResponseHandler = null;
0 ignored issues
show
Unused Code introduced by
$newResponseHandler is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
971
972
        if ($responseHandler instanceof ResponseHandlerInterface) {
973
            $newResponseHandler = $responseHandler;
974
        } else {
975
            $newResponseHandler = new ResponseHandlerBase();
976
        }
977
978
        return $newResponseHandler;
979
    }
980
}
981