1 | <?php |
||
22 | class HttpClient implements HttpClientInterface |
||
23 | { |
||
24 | const CONTENT_TYPE_JSON_API = 'application/vnd.api+json'; |
||
25 | |||
26 | /** |
||
27 | * Options possible to configure |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | static protected $possibleOptions = ['returnBadResponse']; |
||
32 | |||
33 | /** |
||
34 | * @var HttpClientInterface |
||
35 | */ |
||
36 | protected $client; |
||
37 | |||
38 | /** |
||
39 | * @var DocumentHydrator |
||
40 | */ |
||
41 | protected $hydrator; |
||
42 | |||
43 | /** |
||
44 | * Return bad response instead of throwing an exception |
||
45 | * |
||
46 | * @var bool |
||
47 | */ |
||
48 | protected $returnBadResponse = false; |
||
49 | |||
50 | /** |
||
51 | * HttpClient constructor. |
||
52 | * |
||
53 | * @param HttpClientInterface $client |
||
54 | * @param DocumentHydrator $hydrator |
||
55 | * @param array $options |
||
56 | */ |
||
57 | 7 | public function __construct(HttpClientInterface $client, DocumentHydrator $hydrator, array $options = []) |
|
71 | |||
72 | /** |
||
73 | * Is the client returns bad response instead of throwing an exception ? |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | 1 | public function isReturnBadResponse(): bool |
|
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | 5 | public function request(RequestInterface $request): ResponseInterface |
|
105 | |||
106 | /** |
||
107 | * Handle request |
||
108 | * |
||
109 | * @param RequestInterface $request |
||
110 | * @return RequestInterface |
||
111 | */ |
||
112 | 5 | protected function handleRequest(RequestInterface $request): RequestInterface |
|
123 | |||
124 | /** |
||
125 | * Handle response |
||
126 | * |
||
127 | * @param ResponseInterface $response |
||
128 | * @return ResponseInterface |
||
129 | */ |
||
130 | 5 | protected function handleResponse(ResponseInterface $response): ResponseInterface |
|
146 | |||
147 | /** |
||
148 | * Create a JsonApi document by serialized data from stream |
||
149 | * |
||
150 | * @param StreamInterface $stream |
||
151 | * @return AbstractDocument |
||
152 | */ |
||
153 | 1 | protected function streamToDocument(StreamInterface $stream): AbstractDocument |
|
164 | |||
165 | /** |
||
166 | * Create a stream contains serialized JsonApi-document |
||
167 | * |
||
168 | * @param AbstractDocument $document |
||
169 | * @return StreamInterface |
||
170 | */ |
||
171 | 1 | protected function documentToStream(AbstractDocument $document): StreamInterface |
|
186 | } |