1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the php-epp2 library. |
5
|
|
|
* |
6
|
|
|
* (c) Gunter Grodotzki <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE file |
9
|
|
|
* that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace AfriCC\EPP\Frame; |
13
|
|
|
|
14
|
|
|
use AfriCC\EPP\AbstractFrame; |
15
|
|
|
use AfriCC\EPP\DOM\DOMTools; |
16
|
|
|
use AfriCC\EPP\Frame\Response\Result; |
17
|
|
|
use DOMNodeList; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @see http://tools.ietf.org/html/rfc5730#section-2.6 |
21
|
|
|
*/ |
22
|
|
|
class Response extends AbstractFrame |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Get Results from response frame |
26
|
|
|
* |
27
|
|
|
* @return Result[] |
28
|
|
|
*/ |
29
|
|
|
public function results() |
30
|
|
|
{ |
31
|
|
|
$results = []; |
32
|
|
|
$nodes = $this->get('//epp:epp/epp:response/epp:result'); |
33
|
|
|
foreach ($nodes as $node) { |
|
|
|
|
34
|
|
|
$results[] = new Result($node); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return $results; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Whether response is successful |
42
|
|
|
* |
43
|
|
|
* @todo On response with multiple codes this fails miserably |
44
|
|
|
* |
45
|
|
|
* @return bool true on succes, false otherwise. |
46
|
|
|
*/ |
47
|
|
|
public function success() |
48
|
|
|
{ |
49
|
|
|
$code = $this->code(); |
50
|
|
|
if ($code >= 1000 && $code < 2000) { |
51
|
|
|
return true; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return false; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get Response code |
59
|
|
|
* |
60
|
|
|
* @todo on response with multiple results this fails miserably |
61
|
|
|
* |
62
|
|
|
* @return int response code |
63
|
|
|
*/ |
64
|
|
|
public function code() |
65
|
|
|
{ |
66
|
|
|
return (int) $this->get('//epp:epp/epp:response/epp:result/@code'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get Response message |
71
|
|
|
* |
72
|
|
|
* @todo check message against multiple responses |
73
|
|
|
* |
74
|
|
|
* @return string message |
75
|
|
|
*/ |
76
|
|
|
public function message() |
77
|
|
|
{ |
78
|
|
|
return (string) $this->get('//epp:epp/epp:response/epp:result/epp:msg/text()'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function clientTransactionId() |
82
|
|
|
{ |
83
|
|
|
$value = $this->get('//epp:epp/epp:response/epp:trID/epp:clTRID/text()'); |
84
|
|
|
if ($value === false) { |
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return (string) $value; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function serverTransactionId() |
92
|
|
|
{ |
93
|
|
|
$value = $this->get('//epp:epp/epp:response/epp:trID/epp:svTRID/text()'); |
94
|
|
|
if ($value === false) { |
95
|
|
|
return; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return (string) $value; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function data() |
102
|
|
|
{ |
103
|
|
|
$nodes = $this->get('//epp:epp/epp:response/epp:resData'); |
104
|
|
|
if ($nodes === false || !($nodes instanceof DOMNodeList) || $nodes->length === 0 || !$nodes->item(0)->hasChildNodes()) { |
105
|
|
|
$data = []; |
106
|
|
|
} else { |
107
|
|
|
$data = DOMTools::nodeToArray($nodes->item(0)); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
// check for extension data |
111
|
|
|
$nodes = $this->get('//epp:epp/epp:response/epp:extension'); |
112
|
|
|
if ($nodes !== false && $nodes instanceof DOMNodeList && $nodes->length > 0 && $nodes->item(0)->hasChildNodes()) { |
113
|
|
|
$data = array_merge_recursive($data, DOMTools::nodeToArray($nodes->item(0))); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $data; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.