1 | <?php |
||
9 | class Response |
||
10 | { |
||
11 | private $method; |
||
12 | private $response; |
||
13 | |||
14 | public function __construct(string $method, $response) |
||
15 | { |
||
16 | $this->method = $method; |
||
17 | |||
18 | $body = $response->getBody()->getContents(); |
||
19 | $this->response = new \SimpleXMLElement($body); |
||
20 | |||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Checks if the response contains an Error |
||
25 | * @method hasError |
||
26 | * @author PA |
||
27 | * @date 2017-01-10 |
||
28 | * @return bool hasError |
||
29 | */ |
||
30 | public function hasError() : bool |
||
31 | { |
||
32 | return ($this->getErrorCode() != 0); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Fetches the Error Code from the Response |
||
37 | * @method getErrorCode |
||
38 | * @author PA |
||
39 | * @date 2017-01-10 |
||
40 | * @return int Error Code |
||
41 | */ |
||
42 | public function getErrorCode() : int |
||
43 | { |
||
44 | return (int) $this->response->ErrCode; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Fetches the Error Message From Response |
||
49 | * @method getError |
||
50 | * @author PA |
||
51 | * @date 2017-01-10 |
||
52 | * @return string Error Message |
||
53 | */ |
||
54 | public function getError() : string |
||
55 | { |
||
56 | return (string) $this->response->ErrDesc; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Converts the response to an Array |
||
61 | * @method toArray |
||
62 | * @throws YourMembershipException |
||
63 | * @author PA |
||
64 | * @date 2017-01-10 |
||
65 | * @return array Response |
||
66 | */ |
||
67 | public function toArray() : array |
||
71 | |||
72 | /** |
||
73 | * Converts the response to an Object |
||
74 | * @method toObject |
||
75 | * @throws YourMembershipException |
||
76 | * @author PA |
||
77 | * @date 2017-01-11 |
||
78 | * @return stdClass Response |
||
79 | */ |
||
80 | public function toObject() : \stdClass |
||
84 | |||
85 | /** |
||
86 | * Unwraps XML Object into either StdClass or Array |
||
87 | * Lossy conversion, attributes are lost from XML |
||
88 | * |
||
89 | * @method unwrapXMLObject |
||
90 | * @throws YourMembershipException |
||
91 | * @author PA |
||
92 | * @date 2017-01-11 |
||
93 | * @param bool $asArray unwrap the object into an array instead of object |
||
94 | * @return mixed|null Unwrapped Response |
||
95 | */ |
||
96 | private function unwrapXMLObject(bool $asArray) |
||
105 | /** |
||
106 | * Returns the Result Count |
||
107 | * @method getResultCount |
||
108 | * @author PA |
||
109 | * @date 2017-01-10 |
||
110 | * @return int|false false if no ResultCount is present |
||
111 | */ |
||
112 | public function getResultCount() : int |
||
123 | |||
124 | } |
||
125 |