|
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\Travel; |
|
24
|
|
|
|
|
25
|
|
|
use Amadeus\Client\ResponseHandler\StandardResponseHandler; |
|
26
|
|
|
use Amadeus\Client\Result; |
|
27
|
|
|
use Amadeus\Client\Result\NotOk; |
|
28
|
|
|
use Amadeus\Client\Session\Handler\SendResult; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* HandlerTravel |
|
32
|
|
|
* |
|
33
|
|
|
* @package Amadeus\Client\ResponseHandler\Travel |
|
34
|
|
|
* @author Artem Zakharchenko <[email protected]> |
|
35
|
|
|
*/ |
|
36
|
|
|
class HandlerTravel extends StandardResponseHandler |
|
37
|
|
|
{ |
|
38
|
|
|
public function analyze(SendResult $response) |
|
39
|
|
|
{ |
|
40
|
|
|
$result = $this->analyzeSimpleResponseErrorCodeAndMessageStatusCode($response); |
|
41
|
|
|
|
|
42
|
|
|
$error = isset($response->responseObject->Error) ? $response->responseObject->Error : null; |
|
43
|
|
|
$rawErrors = []; |
|
44
|
|
|
|
|
45
|
|
|
if ($error === null) { |
|
46
|
|
|
$rawErrors = isset($response->responseObject->Errors->Error) |
|
47
|
|
|
? $response->responseObject->Errors->Error |
|
48
|
|
|
: []; |
|
49
|
|
|
if (!is_array($rawErrors)) { |
|
50
|
|
|
$rawErrors = [$rawErrors]; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if (is_array($error)) { |
|
55
|
|
|
$rawErrors = array_merge($rawErrors, $error); |
|
56
|
|
|
} elseif ($error !== null) { |
|
57
|
|
|
$rawErrors[] = $error; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
foreach ($rawErrors as $rawError) { |
|
61
|
|
|
$result->setStatus(Result::STATUS_ERROR); |
|
62
|
|
|
$result->messages[] = new NotOk( |
|
63
|
|
|
isset($rawError->Code) ? $rawError->Code : '', |
|
64
|
|
|
isset($rawError->DescText) ? $rawError->DescText : '' |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if ($response = isset($result->response->Response) ? $result->response->Response : null) { |
|
69
|
|
|
$result->response = $response; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $result; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|