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 addHeaders(array $headers) |
||
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). |
||
98 | * |
||
99 | * @param MarketFilter $filter |
||
100 | * @return Client |
||
101 | */ |
||
102 | public function setFilter(MarketFilter $filter) { |
||
106 | |||
107 | /** |
||
108 | * Setter for request locale. |
||
109 | * It's optional, so we only pass a value if there is one |
||
110 | * |
||
111 | * @param string|null $locale |
||
112 | * @return Client |
||
113 | */ |
||
114 | public function setLocale($locale) { |
||
120 | |||
121 | /** |
||
122 | * Dispatch the request and provide hooks for error handling for the response. |
||
123 | * |
||
124 | * @return object stdClass |
||
125 | */ |
||
126 | public function send() |
||
144 | |||
145 | /** |
||
146 | * Get status code from http response. |
||
147 | * |
||
148 | * @param Response $response |
||
149 | * @return integer |
||
150 | */ |
||
151 | protected function getStatus(Response $response) |
||
155 | |||
156 | /** |
||
157 | * Get http response body, cast to json and decode. |
||
158 | * |
||
159 | * @param Response object $response |
||
160 | * @return array |
||
161 | */ |
||
162 | protected function getBody(Response $response) |
||
166 | |||
167 | /** |
||
168 | * Stub for http exception handling. |
||
169 | * |
||
170 | * @param Integer $status |
||
171 | * @return void |
||
172 | */ |
||
173 | protected function handleHttpException($status) { |
||
176 | |||
177 | /** |
||
178 | * Stub for API exception handling. |
||
179 | * |
||
180 | * @param String $exception |
||
181 | * @return void |
||
182 | */ |
||
183 | protected function handleApiException($exception) { |
||
186 | } |
||
187 |
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: