1 | <?php |
||
19 | abstract class AbstractCoreApiClient implements LoggerAwareInterface |
||
20 | { |
||
21 | use LoggerAwareTrait; |
||
22 | |||
23 | /** |
||
24 | * @const string |
||
25 | */ |
||
26 | const OPT_VIDEO_MANAGER_ID = 'videoManagerId'; |
||
27 | |||
28 | /** |
||
29 | * @var ClientInterface The Guzzle HTTP client |
||
30 | */ |
||
31 | protected $httpClient; |
||
32 | |||
33 | /** |
||
34 | * @var Serializer The JMS Serializer instance |
||
35 | */ |
||
36 | protected $serializer; |
||
37 | |||
38 | /** |
||
39 | * @var CacheItemPoolInterface PSR6 cache pool implementation |
||
40 | */ |
||
41 | protected $cacheItemPool; |
||
42 | |||
43 | /** |
||
44 | * @var mixed time-to-live for cached responses |
||
45 | * The type of this property might be integer, \DateInterval or null |
||
46 | * |
||
47 | * @see CacheItemInterface::expiresAfter() |
||
48 | */ |
||
49 | protected $cacheTtl; |
||
50 | |||
51 | /** |
||
52 | * ApiClient constructor. |
||
53 | * |
||
54 | * @param ClientInterface $httpClient |
||
55 | * @param Serializer $serializer |
||
56 | * @param CacheItemPoolInterface $cacheItemPool |
||
57 | * @param int $cacheTtl |
||
58 | */ |
||
59 | public function __construct( |
||
70 | |||
71 | /** |
||
72 | * Perform the actual request in the implementation classes. |
||
73 | * |
||
74 | * @param string $method |
||
75 | * @param string $uri |
||
76 | * @param array $options |
||
77 | * |
||
78 | * @return mixed |
||
79 | */ |
||
80 | abstract protected function _doRequest($method, $uri, $options); |
||
81 | |||
82 | /** |
||
83 | * Make a request to the API and serialize the result according to our |
||
84 | * serialization strategy. |
||
85 | * |
||
86 | * @param string $method |
||
87 | * @param string $uri |
||
88 | * @param array $options |
||
89 | * |
||
90 | * @return object|ResponseInterface |
||
91 | */ |
||
92 | protected function makeRequest($method, $uri, $options) |
||
130 | |||
131 | /** |
||
132 | * Deserialize a response into an instance of it's associated class. |
||
133 | * |
||
134 | * @param string $data |
||
135 | * @param string $serialisationClass |
||
136 | * |
||
137 | * @return object |
||
138 | */ |
||
139 | protected function deserialize($data, $serialisationClass) |
||
143 | |||
144 | /** |
||
145 | * Helper method to build the JSON data array for making a request |
||
146 | * with ::makeRequest(). Optional parameters with empty or null value will be |
||
147 | * omitted from the return value. |
||
148 | * |
||
149 | * Examples: |
||
150 | * |
||
151 | * $this->buildJsonParameters(['title' => 'test'], ['description' => '', 'bla' => 'test']) |
||
152 | * |
||
153 | * Would result in: |
||
154 | * |
||
155 | * [ |
||
156 | * 'title' => 'test', |
||
157 | * 'bla' => 'test', |
||
158 | * ] |
||
159 | * |
||
160 | * @param array $required |
||
161 | * @param array $optional |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | protected function buildJsonParameters(array $required, array $optional) |
||
183 | |||
184 | /** |
||
185 | * Generates the cache key based on the class name, request method, uri and options. |
||
186 | * |
||
187 | * @param string $method |
||
188 | * @param string $uri |
||
189 | * @param array $options |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | private function generateCacheKey($method, $uri, array $options = []) |
||
197 | |||
198 | /** |
||
199 | * Checks if the request may be cached. |
||
200 | * |
||
201 | * @param string $method |
||
202 | * @param string $uri |
||
203 | * @param array $options |
||
204 | * @param mixed $response |
||
205 | * |
||
206 | * @return bool |
||
207 | */ |
||
208 | private function isCachable($method, $uri, array $options, $response) |
||
215 | |||
216 | /** |
||
217 | * Serializes the provided response to a string, suitable for caching. |
||
218 | * The type of the $response argument varies depending on the guzzle version. |
||
219 | * |
||
220 | * @param mixed $response |
||
221 | * |
||
222 | * @return string |
||
223 | */ |
||
224 | abstract protected function serializeResponse($response); |
||
225 | |||
226 | /** |
||
227 | * Unserializes the serialized response into a response object. |
||
228 | * The return type varies depending on the guzzle version. |
||
229 | * |
||
230 | * @param string $serialized |
||
231 | * |
||
232 | * @return mixed |
||
233 | * |
||
234 | * @throws Exception |
||
235 | */ |
||
236 | abstract protected function unserializeResponse($serialized); |
||
237 | } |
||
238 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.