Completed
Push — develop ( a8951f...6805ee )
by Dieter
05:48
created

Client::getLastRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
 * - implement more PNR_AddMultiElements:
42
 *      OSI segment
43
 * - implement messages on supported messages todo section
44
 *
45
 * @package Amadeus
46
 * @author Dieter Devlieghere <[email protected]>
47
 */
48
class Client
49
{
50
    /**
51
     * Amadeus SOAP header version 1
52
     */
53
    const HEADER_V1 = "1";
54
    /**
55
     * Amadeus SOAP header version 2
56
     */
57
    const HEADER_V2 = "2";
58
    /**
59
     * Amadeus SOAP header version 4
60
     */
61
    const HEADER_V4 = "4";
62
63
    /**
64
     * Version string
65
     *
66
     * @var string
67
     */
68
    const version = "0.0.1dev";
69
70
    /**
71
     * An identifier string for the library (to be used in Received From entries)
72
     *
73
     * @var string
74
     */
75
    const receivedFromIdentifier = "amabnl-amadeus-ws-client";
76
77
    /**
78
     * Session Handler will be sending all the messages and handling all session-related things.
79
     *
80
     * @var HandlerInterface
81
     */
82
    protected $sessionHandler;
83
84
    /**
85
     * Request Creator is will create the correct message structure to send to the SOAP server.
86
     *
87
     * @var RequestCreatorInterface
88
     */
89
    protected $requestCreator;
90
91
    /**
92
     * Response Handler will check the received response for errors.
93
     *
94
     * @var ResponseHandlerInterface
95
     */
96
    protected $responseHandler;
97
98
    /**
99
     * Authentication parameters
100
     *
101
     * @var Params\AuthParams
102
     */
103
    protected $authParams;
104
105
    /**
106
     * @var string
107
     */
108
    protected $lastMessage;
109
110
    /**
111
     * Set the session as stateful (true) or stateless (false)
112
     *
113
     * @param bool $newStateful
114
     */
115
    public function setStateful($newStateful)
116
    {
117
        $this->sessionHandler->setStateful($newStateful);
118
    }
119
120
    /**
121
     * @return bool
122
     */
123
    public function isStateful()
124
    {
125
        return $this->sessionHandler->isStateful();
126
    }
127
128
    /**
129
     * Get the last raw XML message that was sent out
130
     *
131
     * @return string|null
132
     */
133
    public function getLastRequest()
134
    {
135
        return $this->sessionHandler->getLastRequest($this->lastMessage);
136
    }
137
138
    /**
139
     * Get the last raw XML message that was received
140
     *
141
     * @return string|null
142
     */
143
    public function getLastResponse()
144
    {
145
        return $this->sessionHandler->getLastResponse($this->lastMessage);
146
    }
147
148
    /**
149
     * Get session information for authenticated session
150
     *
151
     * - sessionId
152
     * - sequenceNr
153
     * - securityToken
154
     *
155
     * @return array|null
156
     */
157
    public function getSessionData()
158
    {
159
        return $this->sessionHandler->getSessionData();
160
    }
161
162
    /**
163
     * Restore a previously used session
164
     *
165
     * To be used when implementing your own session pooling system on legacy Soap Header 2 applications.
166
     *
167
     * @param array $sessionData
168
     * @return bool
169
     */
170
    public function setSessionData(array $sessionData)
171
    {
172
        return $this->sessionHandler->setSessionData($sessionData);
173
    }
174
175
    /**
176
     * Construct Amadeus Web Services client
177
     *
178
     * @param Params $params
179
     */
180
    public function __construct($params)
181
    {
182
        if ($params->authParams instanceof Params\AuthParams) {
183
            $this->authParams = $params->authParams;
184
            if (isset($params->sessionHandlerParams) && $params->sessionHandlerParams instanceof Params\SessionHandlerParams) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
185
                $params->sessionHandlerParams->authParams = $this->authParams;
186
            }
187
        }
188
189
        $this->sessionHandler = $this->loadSessionHandler(
190
            $params->sessionHandler,
191
            $params->sessionHandlerParams
0 ignored issues
show
Bug introduced by
It seems like $params->sessionHandlerParams can be null; however, loadSessionHandler() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
192
        );
193
194
        $this->requestCreator = $this->loadRequestCreator(
195
            $params->requestCreator,
196
            $params->requestCreatorParams,
197
            self::receivedFromIdentifier . "-" .self::version,
198
            $this->sessionHandler->getOriginatorOffice(),
199
            $this->sessionHandler->getMessagesAndVersions()
200
        );
201
202
        $this->responseHandler = $this->loadResponseHandler(
203
            $params->responseHandler
204
        );
205
    }
206
207
    /**
208
     * Authenticate.
209
     *
210
     * Parameters were provided at construction time (sessionhandlerparams)
211
     *
212
     * @return Result
213
     * @throws Exception
214
     */
215
    public function securityAuthenticate()
216
    {
217
        $msgName = 'Security_Authenticate';
218
219
        return $this->callMessage(
220
            $msgName,
221
            new RequestOptions\SecurityAuthenticateOptions(
222
                $this->authParams
223
            ),
224
            [],
225
            false
226
        );
227
    }
228
229
    /**
230
     * Terminate a session - only applicable to non-stateless mode.
231
     *
232
     * @return Result
233
     * @throws Exception
234
     */
235
    public function securitySignOut()
236
    {
237
        $msgName = 'Security_SignOut';
238
239
        return $this->callMessage(
240
            $msgName,
241
            new RequestOptions\SecuritySignOutOptions(),
242
            [],
243
            true
244
        );
245
    }
246
247
    /**
248
     * PNR_Retrieve - Retrieve an Amadeus PNR by record locator
249
     *
250
     * By default, the result will be the PNR_Reply XML as string.
251
     * That way you can easily parse the PNR's contents with XPath.
252
     *
253
     * https://webservices.amadeus.com/extranet/viewService.do?id=27&flavourId=1&menuId=functional
254
     *
255
     * @param RequestOptions\PnrRetrieveOptions $options
256
     * @param array $messageOptions (OPTIONAL) Set ['asString'] = 'false' to get PNR_Reply as a PHP object.
257
     * @return Result
258
     * @throws Exception
259
     */
260
    public function pnrRetrieve(RequestOptions\PnrRetrieveOptions $options, $messageOptions = [])
261
    {
262
        $msgName = 'PNR_Retrieve';
263
264
        return $this->callMessage($msgName, $options, $messageOptions);
265
    }
266
267
    /**
268
     * Create a PNR using PNR_AddMultiElements
269
     *
270
     * @param RequestOptions\PnrCreatePnrOptions $options
271
     * @param array $messageOptions
272
     * @return Result
273
     */
274
    public function pnrCreatePnr(RequestOptions\PnrCreatePnrOptions $options, $messageOptions = [])
275
    {
276
        $msgName = 'PNR_AddMultiElements';
277
278
        return $this->callMessage($msgName, $options, $messageOptions);
279
    }
280
281
    /**
282
     * PNR_AddMultiElements - Create a new PNR or update an existing PNR.
283
     *
284
     * https://webservices.amadeus.com/extranet/viewService.do?id=25&flavourId=1&menuId=functional
285
     *
286
     * @todo implement message creation - maybe split up in separate Create & Modify PNR?
287
     * @param RequestOptions\PnrAddMultiElementsOptions $options
288
     * @param array $messageOptions
289
     * @return Result
290
     */
291
    public function pnrAddMultiElements(RequestOptions\PnrAddMultiElementsOptions $options, $messageOptions = [])
292
    {
293
        $msgName = 'PNR_AddMultiElements';
294
295
        return $this->callMessage($msgName, $options, $messageOptions);
296
    }
297
298
    /**
299
     * PNR_RetrieveAndDisplay - Retrieve an Amadeus PNR by record locator including extra info
300
     *
301
     * This extra info is info you cannot see in the regular PNR, like Offers.
302
     *
303
     * By default, the result will be the PNR_RetrieveAndDisplayReply XML as string.
304
     * That way you can easily parse the PNR's contents with XPath.
305
     *
306
     * Set $messageOptions['asString'] = FALSE to get the response as a PHP object.
307
     *
308
     * https://webservices.amadeus.com/extranet/viewService.do?id=1922&flavourId=1&menuId=functional
309
     *
310
     * @param RequestOptions\PnrRetrieveAndDisplayOptions $options Amadeus Record Locator for PNR
311
     * @param array $messageOptions (OPTIONAL) Set ['asString'] = 'false' to get PNR_RetrieveAndDisplayReply as a PHP object.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
312
     * @return Result
313
     * @throws Exception
314
     **/
315
    public function pnrRetrieveAndDisplay(RequestOptions\PnrRetrieveAndDisplayOptions $options, $messageOptions = [])
316
    {
317
        $msgName = 'PNR_RetrieveAndDisplay';
318
319
        return $this->callMessage($msgName, $options, $messageOptions);
320
    }
321
322
    /**
323
     * PNR_Cancel
324
     *
325
     * @param RequestOptions\PnrCancelOptions $options
326
     * @param array $messageOptions
327
     * @return Result
328
     */
329
    public function pnrCancel(RequestOptions\PnrCancelOptions $options, $messageOptions = [])
330
    {
331
        $msgName = 'PNR_Cancel';
332
333
        return $this->callMessage($msgName, $options, $messageOptions);
334
    }
335
336
    /**
337
     * PNR_DisplayHistory
338
     *
339
     * @param RequestOptions\PnrDisplayHistoryOptions $options
340
     * @param array $messageOptions
341
     * @return Result
342
     */
343
    public function pnrDisplayHistory(RequestOptions\PnrDisplayHistoryOptions $options, $messageOptions = [])
344
    {
345
        $msgName = 'PNR_DisplayHistory';
346
347
        return $this->callMessage($msgName, $options, $messageOptions);
348
    }
349
350
    /**
351
     * Queue_List - get a list of all PNR's on a given queue
352
     *
353
     * https://webservices.amadeus.com/extranet/viewService.do?id=52&flavourId=1&menuId=functional
354
     *
355
     * @param RequestOptions\QueueListOptions $options
356
     * @param array $messageOptions
357
     * @return Result
358
     */
359
    public function queueList(RequestOptions\QueueListOptions $options, $messageOptions = [])
360
    {
361
        $msgName = 'Queue_List';
362
363
        return $this->callMessage($msgName, $options, $messageOptions);
364
    }
365
366
    /**
367
     * Queue_PlacePNR - Place a PNR on a given queue
368
     *
369
     * @param RequestOptions\QueuePlacePnrOptions $options
370
     * @param array $messageOptions
371
     * @return Result
372
     */
373
    public function queuePlacePnr(RequestOptions\QueuePlacePnrOptions $options, $messageOptions = [])
374
    {
375
        $msgName = 'Queue_PlacePNR';
376
377
        return $this->callMessage($msgName, $options, $messageOptions);
378
    }
379
380
    /**
381
     * Queue_RemoveItem - remove an item (a PNR) from a given queue
382
     *
383
     * @param RequestOptions\QueueRemoveItemOptions $options
384
     * @param array $messageOptions
385
     * @return Result
386
     */
387
    public function queueRemoveItem(RequestOptions\QueueRemoveItemOptions $options, $messageOptions = [])
388
    {
389
        $msgName = 'Queue_RemoveItem';
390
391
        return $this->callMessage($msgName, $options, $messageOptions);
392
    }
393
394
    /**
395
     * Queue_MoveItem - move an item (a PNR) from one queue to another.
396
     *
397
     * @param RequestOptions\QueueMoveItemOptions $options
398
     * @param array $messageOptions
399
     * @return Result
400
     */
401
    public function queueMoveItem(RequestOptions\QueueMoveItemOptions $options, $messageOptions = [])
402
    {
403
        $msgName = 'Queue_MoveItem';
404
405
        return $this->callMessage($msgName, $options, $messageOptions);
406
    }
407
408
    /**
409
     * Offer_VerifyOffer
410
     *
411
     * To be called in the context of an open PNR
412
     *
413
     * @param RequestOptions\OfferVerifyOptions $options
414
     * @param array $messageOptions
415
     * @return Result
416
     */
417
    public function offerVerify(RequestOptions\OfferVerifyOptions $options, $messageOptions = [])
418
    {
419
        $msgName = 'Offer_VerifyOffer';
420
421
        return $this->callMessage($msgName, $options, $messageOptions);
422
    }
423
424
    /**
425
     * Offer_ConfirmAirOffer
426
     *
427
     * @param RequestOptions\OfferConfirmAirOptions $options
428
     * @param array $messageOptions
429
     * @return Result
430
     */
431
    public function offerConfirmAir(RequestOptions\OfferConfirmAirOptions $options, $messageOptions = [])
432
    {
433
        $msgName = 'Offer_ConfirmAirOffer';
434
435
        return $this->callMessage($msgName, $options, $messageOptions);
436
    }
437
438
    /**
439
     * Offer_ConfirmHotelOffer
440
     *
441
     * @param RequestOptions\OfferConfirmHotelOptions $options
442
     * @param array $messageOptions
443
     * @return Result
444
     */
445
    public function offerConfirmHotel(RequestOptions\OfferConfirmHotelOptions $options, $messageOptions = [])
446
    {
447
        $msgName = 'Offer_ConfirmHotelOffer';
448
449
        return $this->callMessage($msgName, $options, $messageOptions);
450
    }
451
452
    /**
453
     * Offer_ConfirmCarOffer
454
     *
455
     * @param RequestOptions\OfferConfirmCarOptions $options
456
     * @param array $messageOptions
457
     * @return Result
458
     */
459
    public function offerConfirmCar(RequestOptions\OfferConfirmCarOptions $options, $messageOptions = [])
460
    {
461
        $msgName = 'Offer_ConfirmCarOffer';
462
463
        return $this->callMessage($msgName, $options, $messageOptions);
464
    }
465
466
    /**
467
     * Fare_MasterPricerTravelBoardSearch
468
     *
469
     * @param RequestOptions\FareMasterPricerTbSearch $options
470
     * @param array $messageOptions
471
     * @return Result
472
     */
473
    public function fareMasterPricerTravelBoardSearch(RequestOptions\FareMasterPricerTbSearch $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
474
    {
475
        $msgName = 'Fare_MasterPricerTravelBoardSearch';
476
477
        return $this->callMessage($msgName, $options, $messageOptions);
478
    }
479
480
    /**
481
     * Fare_PricePnrWithBookingClass
482
     *
483
     * @param RequestOptions\FarePricePnrWithBookingClassOptions $options
484
     * @param array $messageOptions
485
     * @return Result
486
     */
487
    public function farePricePnrWithBookingClass(RequestOptions\FarePricePnrWithBookingClassOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 131 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
488
    {
489
        $msgName = 'Fare_PricePNRWithBookingClass';
490
491
        return $this->callMessage($msgName, $options, $messageOptions);
492
    }
493
494
    /**
495
     * Fare_InformativePricingWithoutPNR
496
     *
497
     * @param RequestOptions\FareInformativePricingWithoutPnrOptions $options
498
     * @param array $messageOptions
499
     * @return Result
500
     */
501
    public function fareInformativePricingWithoutPnr(RequestOptions\FareInformativePricingWithoutPnrOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 139 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
502
    {
503
        $msgName = 'Fare_InformativePricingWithoutPNR';
504
505
        return $this->callMessage($msgName, $options, $messageOptions);
506
    }
507
508
    /**
509
     * Fare_CheckRules
510
     *
511
     * @param RequestOptions\FareCheckRulesOptions $options
512
     * @param array $messageOptions
513
     * @return Result
514
     */
515
    public function fareCheckRules(RequestOptions\FareCheckRulesOptions $options, $messageOptions = [])
516
    {
517
        $msgName = 'Fare_CheckRules';
518
519
        return $this->callMessage($msgName, $options, $messageOptions);
520
    }
521
522
    /**
523
     * Fare_ConvertCurrency
524
     *
525
     * @param RequestOptions\FareConvertCurrencyOptions $options
526
     * @param array $messageOptions
527
     * @return Result
528
     */
529
    public function fareConvertCurrency(RequestOptions\FareConvertCurrencyOptions $options, $messageOptions = [])
530
    {
531
        $msgName = 'Fare_ConvertCurrency';
532
533
        return $this->callMessage($msgName, $options, $messageOptions);
534
    }
535
536
    /**
537
     * Air_MultiAvailability
538
     *
539
     * @param RequestOptions\AirMultiAvailabilityOptions $options
540
     * @param array $messageOptions
541
     * @return Result
542
     */
543
    public function airMultiAvailability(RequestOptions\AirMultiAvailabilityOptions $options, $messageOptions = [])
544
    {
545
        $msgName = 'Air_MultiAvailability';
546
547
        return $this->callMessage($msgName, $options, $messageOptions);
548
    }
549
550
    /**
551
     * Air_SellFromRecommendation
552
     *
553
     * @param RequestOptions\AirSellFromRecommendationOptions $options
554
     * @param array $messageOptions
555
     * @return Result
556
     */
557
    public function airSellFromRecommendation(RequestOptions\AirSellFromRecommendationOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
558
    {
559
        $msgName = 'Air_SellFromRecommendation';
560
561
        return $this->callMessage($msgName, $options, $messageOptions);
562
    }
563
564
    /**
565
     * Air_FlightInfo
566
     *
567
     * @param RequestOptions\AirFlightInfoOptions $options
568
     * @param array $messageOptions
569
     * @return Result
570
     */
571
    public function airFlightInfo(RequestOptions\AirFlightInfoOptions $options, $messageOptions = [])
572
    {
573
        $msgName = 'Air_FlightInfo';
574
575
        return $this->callMessage($msgName, $options, $messageOptions);
576
    }
577
578
    /**
579
     * Air_RetrieveSeatMap
580
     *
581
     * @param RequestOptions\AirRetrieveSeatMapOptions $options
582
     * @param array $messageOptions
583
     * @return Result
584
     */
585
    public function airRetrieveSeatMap(RequestOptions\AirRetrieveSeatMapOptions $options, $messageOptions = [])
586
    {
587
        $msgName = 'Air_RetrieveSeatMap';
588
589
        return $this->callMessage($msgName, $options, $messageOptions);
590
    }
591
592
    /**
593
     * Command_Cryptic
594
     *
595
     * @param RequestOptions\CommandCrypticOptions $options
596
     * @param array $messageOptions
597
     * @return Result
598
     */
599
    public function commandCryptic(RequestOptions\CommandCrypticOptions $options, $messageOptions = [])
600
    {
601
        $msgName = 'Command_Cryptic';
602
603
        return $this->callMessage($msgName, $options, $messageOptions);
604
    }
605
606
    /**
607
     * MiniRule_GetFromPricingRec
608
     *
609
     * @param RequestOptions\MiniRuleGetFromPricingRecOptions $options
610
     * @param array $messageOptions
611
     * @return Result
612
     */
613
    public function miniRuleGetFromPricingRec(RequestOptions\MiniRuleGetFromPricingRecOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
614
    {
615
        $msgName = 'MiniRule_GetFromPricingRec';
616
617
        return $this->callMessage($msgName, $options, $messageOptions);
618
    }
619
620
    /**
621
     * Info_EncodeDecodeCity
622
     *
623
     * @param RequestOptions\InfoEncodeDecodeCityOptions $options
624
     * @param array $messageOptions
625
     * @return Result
626
     */
627
    public function infoEncodeDecodeCity(RequestOptions\InfoEncodeDecodeCityOptions $options, $messageOptions = [])
628
    {
629
        $msgName = 'Info_EncodeDecodeCity';
630
631
        return $this->callMessage($msgName, $options, $messageOptions);
632
    }
633
634
635
    /**
636
     * Ticket_CreateTSTFromPricing
637
     *
638
     * @param RequestOptions\TicketCreateTstFromPricingOptions $options
639
     * @param array $messageOptions
640
     * @return Result
641
     */
642
    public function ticketCreateTSTFromPricing(RequestOptions\TicketCreateTstFromPricingOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
643
    {
644
        $msgName = 'Ticket_CreateTSTFromPricing';
645
646
        return $this->callMessage($msgName, $options, $messageOptions);
647
    }
648
649
    /**
650
     * DocIssuance_IssueTicket
651
     *
652
     * @param RequestOptions\DocIssuanceIssueTicketOptions $options
653
     * @param array $messageOptions
654
     * @return Result
655
     */
656
    public function docIssuanceIssueTicket(RequestOptions\DocIssuanceIssueTicketOptions $options, $messageOptions = [])
657
    {
658
        $msgName = 'DocIssuance_IssueTicket';
659
660
        return $this->callMessage($msgName, $options, $messageOptions);
661
    }
662
663
    /**
664
     * PriceXplorer_ExtremeSearch
665
     *
666
     * @param RequestOptions\PriceXplorerExtremeSearchOptions $options
667
     * @param array $messageOptions
668
     * @return Result
669
     */
670
    public function priceXplorerExtremeSearch(RequestOptions\PriceXplorerExtremeSearchOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
671
    {
672
        $msgName = 'PriceXplorer_ExtremeSearch';
673
674
        return $this->callMessage($msgName, $options, $messageOptions);
675
    }
676
677
    /**
678
     * SalesReports_DisplayQueryReport
679
     *
680
     * @param RequestOptions\SalesReportsDisplayQueryReportOptions $options
681
     * @param array $messageOptions
682
     * @return Result
683
     */
684
    public function salesReportsDisplayQueryReport(RequestOptions\SalesReportsDisplayQueryReportOptions $options, $messageOptions = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
685
    {
686
        $msgName = 'SalesReports_DisplayQueryReport';
687
688
        return $this->callMessage($msgName, $options, $messageOptions);
689
    }
690
691
    /**
692
     * Call a message with the given parameters
693
     *
694
     * @param string $messageName
695
     * @param RequestOptions\RequestOptionsInterface $options
696
     * @param array $messageOptions
697
     * @param bool $endSession
698
     * @return Result
699
     * @throws Client\Exception
700
     * @throws Client\Struct\InvalidArgumentException
701
     * @throws Client\InvalidMessageException
702
     * @throws Client\RequestCreator\MessageVersionUnsupportedException
703
     * @throws \RuntimeException
704
     * @throws \InvalidArgumentException
705
     * @throws \SoapFault
706
     */
707
    protected function callMessage($messageName, $options, $messageOptions, $endSession = false)
708
    {
709
        $messageOptions = $this->makeMessageOptions($messageOptions, $endSession);
710
711
        $this->lastMessage = $messageName;
712
713
        $sendResult = $this->sessionHandler->sendMessage(
714
            $messageName,
715
            $this->requestCreator->createRequest(
716
                $messageName,
717
                $options
718
            ),
719
            $messageOptions
720
        );
721
722
        return $this->responseHandler->analyzeResponse(
723
            $sendResult,
724
            $messageName
725
        );
726
    }
727
728
    /**
729
     * Make message options
730
     *
731
     * Message options are meta options when sending a message to the amadeus web services
732
     * - (if stateful) should we end the current session after sending this call?
733
     * - ... ?
734
     *
735
     * @param array $incoming The Message options chosen by the caller - if any.
736
     * @param bool $endSession Switch if you want to terminate the current session after making the call.
737
     * @return array
738
     */
739
    protected function makeMessageOptions(array $incoming, $endSession = false)
740
    {
741
        $options = [
742
            'endSession' => $endSession
743
        ];
744
745
        if (array_key_exists('endSession', $incoming)) {
746
            $options['endSession'] = $incoming['endSession'];
747
        }
748
749
        return $options;
750
    }
751
752
    /**
753
     * Load the session handler
754
     *
755
     * Either load the provided session handler or create one depending on incoming parameters.
756
     *
757
     * @param HandlerInterface|null $sessionHandler
758
     * @param Params\SessionHandlerParams $params
759
     * @return HandlerInterface
760
     */
761
    protected function loadSessionHandler($sessionHandler, $params)
762
    {
763
        $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...
764
765
        if ($sessionHandler instanceof HandlerInterface) {
766
            $newSessionHandler = $sessionHandler;
767
        } else {
768
            $newSessionHandler = HandlerFactory::createHandler($params);
769
        }
770
771
        return $newSessionHandler;
772
    }
773
774
    /**
775
     * Load a request creator
776
     *
777
     * A request creator is responsible for generating the correct request to send.
778
     *
779
     * @param RequestCreatorInterface|null $requestCreator
780
     * @param Params\RequestCreatorParams $params
781
     * @param string $libIdentifier Library identifier & version string (for Received From)
782
     * @param string $originatorOffice The Office we are signed in with.
783
     * @param array $mesVer Messages & Versions array of active messages in the WSDL
784
     * @return RequestCreatorInterface
785
     * @throws \RuntimeException
786
     */
787
    protected function loadRequestCreator($requestCreator, $params, $libIdentifier, $originatorOffice, $mesVer)
788
    {
789
        $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...
790
791
        if ($requestCreator instanceof RequestCreatorInterface) {
792
            $newRequestCreator = $requestCreator;
793
        } else {
794
            $params->originatorOfficeId = $originatorOffice;
795
            $params->messagesAndVersions = $mesVer;
796
797
            $newRequestCreator = RequestCreatorFactory::createRequestCreator(
798
                $params,
799
                $libIdentifier
800
            );
801
        }
802
803
        return $newRequestCreator;
804
    }
805
806
    /**
807
     * Load a response handler
808
     *
809
     * @param ResponseHandlerInterface|null $responseHandler
810
     *
811
     * @return ResponseHandlerInterface
812
     * @throws \RuntimeException
813
     */
814
    protected function loadResponseHandler($responseHandler)
815
    {
816
        $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...
817
818
        if ($responseHandler instanceof ResponseHandlerInterface) {
819
            $newResponseHandler = $responseHandler;
820
        } else {
821
            $newResponseHandler = new ResponseHandlerBase();
822
        }
823
824
        return $newResponseHandler;
825
    }
826
}
827