1 | <?php |
||
28 | class ComradeReader |
||
29 | { |
||
30 | /** @var ClientInterface $client */ |
||
31 | protected $client; |
||
32 | |||
33 | /** @var string $url */ |
||
34 | protected $url; |
||
35 | |||
36 | /** @var string $secretToken */ |
||
37 | protected $secretToken; |
||
38 | |||
39 | /** @var string $tokenFieldName */ |
||
40 | protected $tokenFieldName = 'token'; |
||
41 | |||
42 | /** @var object $serializer */ |
||
43 | protected $serializer; |
||
44 | |||
45 | /** @var CacheProvider $cache */ |
||
46 | protected $cache; |
||
47 | |||
48 | /** @var string[] $headers */ |
||
49 | protected $headers = []; |
||
50 | |||
51 | /** |
||
52 | * @param string $apiUrl |
||
53 | * @param string $apiKey |
||
54 | * @param object $serializer A Symfony serializer Component, JMS Serializer or other |
||
55 | * @param CacheProvider $cache |
||
56 | */ |
||
57 | public function __construct( |
||
68 | |||
69 | /** |
||
70 | * @param array $headers |
||
71 | * @return $this |
||
72 | */ |
||
73 | public function setHeaders(array $headers) |
||
78 | |||
79 | /** |
||
80 | * @return ClientInterface |
||
81 | */ |
||
82 | protected function getClient() |
||
97 | |||
98 | /** |
||
99 | * @param string $tokenFieldName |
||
100 | * @return ComradeReader |
||
101 | */ |
||
102 | public function setTokenFieldName($tokenFieldName) |
||
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getTokenFieldName() |
||
115 | |||
116 | /** |
||
117 | * @return array |
||
118 | */ |
||
119 | protected function getConnectionOptions() |
||
128 | |||
129 | /** |
||
130 | * Make a request to the server |
||
131 | * and return a decoded response |
||
132 | * |
||
133 | * @param string $method |
||
134 | * @param string $url |
||
135 | * @param ParametersBagInterface|null $parameters |
||
136 | * @param int $cacheLifeTime |
||
137 | * |
||
138 | * @throws InvalidArgumentException |
||
139 | * @throws ResourceNotFoundException |
||
140 | * |
||
141 | * @return ComradeDeserializer |
||
142 | */ |
||
143 | public function request( |
||
187 | |||
188 | /** |
||
189 | * Alias to request() |
||
190 | * |
||
191 | * @param string $url |
||
192 | * @param ParametersBagInterface|null $parameters |
||
193 | * @param int $cacheLifeTime |
||
194 | * |
||
195 | * @throws ResourceNotFoundException |
||
196 | * @return ComradeDeserializer |
||
197 | */ |
||
198 | public function get( |
||
205 | |||
206 | /** |
||
207 | * Alias to request(), with "POST" preselected as a HTTP method |
||
208 | * |
||
209 | * @param string $url |
||
210 | * @param ParametersBagInterface|null $parameters |
||
211 | * @param int $cacheLifeTime |
||
212 | * |
||
213 | * @throws ResourceNotFoundException |
||
214 | * @return ComradeDeserializer |
||
215 | */ |
||
216 | public function post( |
||
223 | |||
224 | /** |
||
225 | * Alias to request(), with "PUT" preselected as a HTTP method |
||
226 | * |
||
227 | * @param string $url |
||
228 | * @param ParametersBagInterface|null $parameters |
||
229 | * @param int $cacheLifeTime |
||
230 | * |
||
231 | * @throws ResourceNotFoundException |
||
232 | * @return ComradeDeserializer |
||
233 | */ |
||
234 | public function put( |
||
241 | |||
242 | /** |
||
243 | * Alias to request(), with "DELETE" preselected as a HTTP method |
||
244 | * |
||
245 | * @param string $url |
||
246 | * @param ParametersBagInterface|null $parameters |
||
247 | * @param int $cacheLifeTime |
||
248 | * |
||
249 | * @throws ResourceNotFoundException |
||
250 | * @return ComradeDeserializer |
||
251 | */ |
||
252 | public function delete( |
||
259 | |||
260 | /** |
||
261 | * @param string $path |
||
262 | * @return string |
||
263 | */ |
||
264 | protected function getPreparedRequestUrl($path) |
||
268 | |||
269 | /** |
||
270 | * @param string $method |
||
271 | * @param string $url |
||
272 | * @param array $parameters |
||
273 | * @return string |
||
274 | */ |
||
275 | protected function getCacheId($method, $url, $parameters) |
||
279 | |||
280 | /** |
||
281 | * @param string $url |
||
282 | * @param string $method |
||
283 | * @param ParametersBagInterface $parametersBag |
||
284 | * |
||
285 | * @throws \InvalidArgumentException |
||
286 | * @return string |
||
287 | */ |
||
288 | protected function buildParameters($url, $method, ParametersBagInterface $parametersBag = null) |
||
296 | } |