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\ResponseHandler\PNR; |
24
|
|
|
|
25
|
|
|
use Amadeus\Client\ResponseHandler\StandardResponseHandler; |
26
|
|
|
use Amadeus\Client\Result; |
27
|
|
|
use Amadeus\Client\Session\Handler\SendResult; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* HandlerRetrieve |
31
|
|
|
* |
32
|
|
|
* @package Amadeus\Client\ResponseHandler\PNR |
33
|
|
|
* @author Dieter Devlieghere <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class HandlerRetrieve extends StandardResponseHandler |
36
|
|
|
{ |
37
|
|
|
const Q_G_ERR = "//m:generalErrorInfo//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode"; |
38
|
|
|
const Q_G_MSG = "//m:generalErrorInfo/m:errorWarningDescription/m:freeText"; |
39
|
|
|
const Q_G_OLD_ERR = "//m:generalErrorInfo//m:messageErrorInformation/m:errorDetail/m:errorCode"; |
40
|
|
|
const Q_G_OLD_MSG = "//m:generalErrorInfo/m:messageErrorText/m:text"; |
41
|
|
|
const Q_S_ERR = "//m:originDestinationDetails//m:errorInfo/m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode"; |
42
|
|
|
const Q_S_MSG = "//m:originDestinationDetails//m:errorInfo/m:errorWarningDescription/m:freeText"; |
43
|
|
|
const Q_E_ERR = "//m:dataElementsIndiv/m:elementErrorInformation/m:errorOrWarningCodeDetails//m:errorCode"; |
44
|
|
|
const Q_E_MSG = "//m:dataElementsIndiv//m:elementErrorInformation/m:errorWarningDescription/m:freeText"; |
45
|
|
|
const Q_P_ERR = "//m:travellerInfo/m:nameError/m:errorOrWarningCodeDetails//m:errorCode"; |
46
|
|
|
const Q_P_MSG = "//m:travellerInfo/m:nameError/m:errorWarningDescription/m:freeText"; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Analysing a PNR_Reply |
50
|
|
|
* |
51
|
|
|
* @param SendResult $response |
52
|
|
|
* @return Result |
53
|
|
|
*/ |
54
|
45 |
|
public function analyze(SendResult $response) |
55
|
|
|
{ |
56
|
45 |
|
$analyzeResponse = new Result($response); |
57
|
|
|
|
58
|
45 |
|
$domXpath = $this->makeDomXpath($response->responseXml); |
59
|
|
|
|
60
|
|
|
//General Errors: |
61
|
45 |
|
$errorCodeNodeList = $domXpath->query(self::Q_G_ERR); |
62
|
|
|
|
63
|
45 |
|
if ($errorCodeNodeList->length > 0) { |
64
|
10 |
|
$analyzeResponse->status = Result::STATUS_ERROR; |
65
|
|
|
|
66
|
10 |
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
67
|
10 |
|
$errorTextNodeList = $domXpath->query(self::Q_G_MSG); |
68
|
10 |
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
69
|
|
|
|
70
|
10 |
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'general'); |
71
|
4 |
|
} |
72
|
|
|
|
73
|
|
|
//General Errors - PNR_Reply v 14.1 and below: |
74
|
45 |
|
$errorCodeNodeList = $domXpath->query(self::Q_G_OLD_ERR); |
75
|
|
|
|
76
|
45 |
|
if ($errorCodeNodeList->length > 0) { |
77
|
5 |
|
$analyzeResponse->status = Result::STATUS_ERROR; |
78
|
|
|
|
79
|
5 |
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
80
|
5 |
|
$errorTextNodeList = $domXpath->query(self::Q_G_OLD_MSG); |
81
|
5 |
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
82
|
|
|
|
83
|
5 |
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'general'); |
84
|
2 |
|
} |
85
|
|
|
|
86
|
|
|
//Passenger error |
87
|
45 |
|
$errorCodeNodeList = $domXpath->query(self::Q_P_ERR); |
88
|
|
|
|
89
|
45 |
|
if ($errorCodeNodeList->length > 0) { |
90
|
5 |
|
$analyzeResponse->status = Result::STATUS_ERROR; |
91
|
|
|
|
92
|
5 |
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
93
|
5 |
|
$errorTextNodeList = $domXpath->query(self::Q_P_MSG); |
94
|
5 |
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
95
|
|
|
|
96
|
5 |
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'passenger'); |
97
|
2 |
|
} |
98
|
|
|
|
99
|
|
|
//Segment errors: |
100
|
45 |
|
$errorCodeNodeList = $domXpath->query(self::Q_S_ERR); |
101
|
|
|
|
102
|
45 |
|
if ($errorCodeNodeList->length > 0) { |
103
|
5 |
|
$analyzeResponse->status = Result::STATUS_ERROR; |
104
|
|
|
|
105
|
5 |
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
106
|
5 |
|
$errorTextNodeList = $domXpath->query(self::Q_S_MSG); |
107
|
5 |
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
108
|
|
|
|
109
|
5 |
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'segment'); |
110
|
2 |
|
} |
111
|
|
|
|
112
|
|
|
//Element errors: |
113
|
45 |
|
$errorCodeNodeList = $domXpath->query(self::Q_E_ERR); |
114
|
|
|
|
115
|
45 |
|
if ($errorCodeNodeList->length > 0) { |
116
|
5 |
|
$analyzeResponse->status = Result::STATUS_ERROR; |
117
|
|
|
|
118
|
5 |
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
119
|
|
|
|
120
|
5 |
|
$errorTextNodeList = $domXpath->query(self::Q_E_MSG); |
121
|
5 |
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
122
|
|
|
|
123
|
5 |
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'element'); |
124
|
2 |
|
} |
125
|
|
|
|
126
|
45 |
|
return $analyzeResponse; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|