1 | <?php |
||
14 | trait HttpTrait |
||
15 | { |
||
16 | /** |
||
17 | * API host url |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $apiHost; |
||
22 | |||
23 | /** |
||
24 | * HTTP client |
||
25 | * |
||
26 | * @var GuzzleHttp\Client |
||
27 | */ |
||
28 | protected $httpClient; |
||
29 | |||
30 | /** |
||
31 | * Prepares and appends parameters, if provided, to the given url. |
||
32 | * |
||
33 | * @param string $url |
||
34 | * @param array $parameters |
||
35 | * @param array $options |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | protected function appendParametersToUrl($url, array $parameters = array(), array $options = array()) |
||
53 | |||
54 | /** |
||
55 | * Returns the yelp client's http client to the given http client. Client. |
||
56 | * |
||
57 | * @return GuzzleHttp\Client|null |
||
58 | */ |
||
59 | public function getHttpClient() |
||
63 | |||
64 | /** |
||
65 | * Creates a PSR-7 Request instance. |
||
66 | * |
||
67 | * @param null|string $method HTTP method for the request. |
||
68 | * @param null|string $uri URI for the request. |
||
69 | * @param array $headers Headers for the message. |
||
70 | * @param string|resource|StreamInterface $body Message body. |
||
71 | * @param string $version HTTP protocol version. |
||
72 | * |
||
73 | * @return GuzzleHttp\Psr7\Request |
||
74 | */ |
||
75 | public function getRequest( |
||
96 | |||
97 | /** |
||
98 | * Sends a request instance and returns a response instance. |
||
99 | * |
||
100 | * WARNING: This method does not attempt to catch exceptions caused by HTTP |
||
101 | * errors! It is recommended to wrap this method in a try/catch block. |
||
102 | * |
||
103 | * @param RequestInterface $request |
||
104 | * @return ResponseInterface |
||
105 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
106 | */ |
||
107 | public function getResponse(RequestInterface $request) |
||
117 | |||
118 | /** |
||
119 | * Updates query params array to apply yelp specific formatting rules. |
||
120 | * |
||
121 | * @param array $params |
||
122 | * @param array $options |
||
123 | * |
||
124 | * @return string|null |
||
125 | */ |
||
126 | protected function prepareQueryParams($params = [], $options = []) |
||
151 | |||
152 | /** |
||
153 | * Makes a request to the Yelp API and returns the response |
||
154 | * |
||
155 | * @param string $path The path of the APi after the domain |
||
156 | * |
||
157 | * @return stdClass The JSON response from the request |
||
158 | * @throws Stevenmaguire\Yelp\Exception\ClientConfigurationException |
||
159 | * @throws Stevenmaguire\Yelp\Exception\HttpException |
||
160 | */ |
||
161 | protected function processRequest(RequestInterface $request) |
||
167 | |||
168 | /** |
||
169 | * Updates the yelp client's http client to the given http client. Client. |
||
170 | * |
||
171 | * @param GuzzleHttp\Client $client |
||
172 | * |
||
173 | * @return mixed |
||
174 | */ |
||
175 | public function setHttpClient(HttpClient $client) |
||
181 | } |
||
182 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: