1 | <?php |
||
11 | class Client |
||
12 | { |
||
13 | protected $guzzleClient; |
||
14 | |||
15 | protected $method = 'get'; |
||
16 | |||
17 | protected $uri = ''; |
||
18 | |||
19 | protected $options = [ ]; |
||
20 | |||
21 | /** |
||
22 | * instantiate Guzzle client (unless one is injected). |
||
23 | * |
||
24 | * @param GuzzleClient $client |
||
25 | * @return void |
||
26 | */ |
||
27 | public function __construct($client = null) |
||
32 | |||
33 | /** |
||
34 | * Setter for request method. |
||
35 | * |
||
36 | * @param string $method |
||
37 | * @return Client |
||
38 | */ |
||
39 | public function setMethod(string $method) |
||
44 | |||
45 | /** |
||
46 | * Setter for request end point URI. |
||
47 | * |
||
48 | * @param string $endPoint |
||
49 | * @return Client |
||
50 | */ |
||
51 | public function setEndPoint(string $endPoint) |
||
56 | |||
57 | /** |
||
58 | * Setter for request headers. |
||
59 | * |
||
60 | * @param array $headers |
||
61 | * @return Client |
||
62 | */ |
||
63 | public function addHeader(array $header) |
||
64 | { |
||
65 | $this->options[ 'headers' ][] = $header; |
||
66 | return $this; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Setter for authentication headers. |
||
71 | * |
||
72 | * @param array $headers |
||
73 | * @return Client |
||
74 | */ |
||
75 | public function authHeaders(array $headers = [ ]) |
||
83 | |||
84 | /** |
||
85 | * Setter for request form data. |
||
86 | * |
||
87 | * @param array $formData |
||
88 | * @return Client |
||
89 | */ |
||
90 | public function setFormData(array $formData) |
||
95 | |||
96 | /** |
||
97 | * Setter for request filter(s). mandatory, but can be empty |
||
98 | * |
||
99 | * @param array|null $filter |
||
100 | * @return Client |
||
101 | */ |
||
102 | public function setFilter($filter = null) |
||
107 | |||
108 | /** |
||
109 | * Setter for optional market projection, i.e. what market-related data should be returned. |
||
110 | * |
||
111 | * @param array|null $marketProjection |
||
112 | * @return Client |
||
113 | */ |
||
114 | public function setMarketProjection($marketProjection = null) |
||
121 | |||
122 | /** |
||
123 | * Setter for optional request sort. |
||
124 | * |
||
125 | * @param string|null $locale |
||
126 | * @return Client |
||
127 | */ |
||
128 | public function setSort($sort) |
||
135 | |||
136 | /** |
||
137 | * Setter for mandatory request max results limiter. |
||
138 | * |
||
139 | * @param integer|null $maxResults |
||
140 | * @return Client |
||
141 | */ |
||
142 | public function setMaxresults($maxResults = 100) |
||
149 | |||
150 | /** |
||
151 | * Setter for optional request locale. |
||
152 | * |
||
153 | * @param string|null $locale |
||
154 | * @return Client |
||
155 | */ |
||
156 | public function setLocale($locale) |
||
163 | |||
164 | /** |
||
165 | * Dispatch the request and provide hooks for error handling for the response. |
||
166 | * |
||
167 | * @return object stdClass |
||
168 | */ |
||
169 | public function send() |
||
187 | |||
188 | /** |
||
189 | * Get status code from http response. |
||
190 | * |
||
191 | * @param Response $response |
||
192 | * @return integer |
||
193 | */ |
||
194 | protected function getStatus(Response $response) |
||
198 | |||
199 | /** |
||
200 | * Get http response body, cast to json and decode. |
||
201 | * |
||
202 | * @param Response object $response |
||
203 | * @return array |
||
204 | */ |
||
205 | protected function getBody(Response $response) |
||
209 | |||
210 | /** |
||
211 | * Stub for http exception handling. |
||
212 | * |
||
213 | * @param Integer $status |
||
214 | * @return void |
||
215 | */ |
||
216 | protected function handleHttpException($status) { |
||
219 | |||
220 | /** |
||
221 | * Stub for API exception handling. |
||
222 | * |
||
223 | * @param String $exception |
||
224 | * @return void |
||
225 | */ |
||
226 | protected function handleApiException($exception) { |
||
229 | } |
||
230 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: