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\Util; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* MsgBodyExtractor |
27
|
|
|
* |
28
|
|
|
* @package Amadeus\Client\Util |
29
|
|
|
* @author Dieter Devlieghere <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class MsgBodyExtractor |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Extracts the message content from the soap envelope (i.e. everything under the soap body) |
35
|
|
|
* |
36
|
|
|
* @param string $soapResponse |
37
|
|
|
* @return string|null |
|
|
|
|
38
|
|
|
*/ |
39
|
44 |
|
public function extract($soapResponse) |
40
|
|
|
{ |
41
|
44 |
|
$messageBody = null; |
|
|
|
|
42
|
|
|
|
43
|
44 |
|
$messageBody = $this->getStringBetween($soapResponse, '<SOAP-ENV:Body>', '</SOAP-ENV:Body>'); |
44
|
|
|
|
45
|
44 |
|
if (empty($messageBody) || false === $messageBody) { |
46
|
8 |
|
$messageBody = $this->getStringBetween($soapResponse, '<soap:Body>', '</soap:Body>'); |
47
|
4 |
|
} |
48
|
|
|
|
49
|
44 |
|
return $messageBody; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get substring between two strings |
54
|
|
|
* |
55
|
|
|
* @param $string |
56
|
|
|
* @param $start |
57
|
|
|
* @param $end |
58
|
|
|
* @return bool|string |
59
|
|
|
*/ |
60
|
44 |
|
private function getStringBetween($string, $start, $end) |
61
|
|
|
{ |
62
|
44 |
|
$startPos = strpos($string, $start) + strlen($start); |
63
|
|
|
|
64
|
44 |
|
$endPos = strlen($string) - strpos($string, $end); |
65
|
|
|
|
66
|
44 |
|
return substr($string, $startPos, -$endPos); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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.