1 | <?php |
||
10 | class ResponseYielder |
||
11 | { |
||
12 | 16 | public static function syncExec($ch) |
|
13 | 16 | { |
|
14 | 16 | if (false === $buffer = curl_exec($ch)) { |
|
15 | 1 | throw new CURLException(curl_error($ch), curl_errno($ch), $ch); |
|
16 | } |
||
17 | 15 | $response = new Response($buffer, $ch); |
|
18 | 14 | if ($response->getStatusCode() >= 300 && |
|
19 | 14 | $response->getStatusCode() < 400 && |
|
20 | 14 | '' !== $url = $response->getHeaderLine('Location')) { |
|
21 | 1 | curl_setopt_array($ch, [ |
|
22 | 1 | CURLOPT_URL => $url, |
|
23 | 1 | CURLOPT_HTTPGET => true, |
|
24 | 1 | CURLOPT_REFERER => curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), |
|
25 | ]); |
||
26 | 1 | return static::syncExec($ch); |
|
27 | } |
||
28 | 14 | return $response; |
|
29 | } |
||
30 | |||
31 | 11 | public static function asyncExec($ch) |
|
32 | 11 | { |
|
33 | 11 | $response = new Response((yield $ch), $ch); |
|
34 | 11 | if ($response->getStatusCode() >= 300 && |
|
35 | 11 | $response->getStatusCode() < 400 && |
|
36 | 11 | '' !== $url = $response->getHeaderLine('Location')) { |
|
37 | 1 | curl_setopt_array($ch, [ |
|
38 | 1 | CURLOPT_URL => $url, |
|
39 | 1 | CURLOPT_HTTPGET => true, |
|
40 | 1 | CURLOPT_REFERER => curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), |
|
41 | ]); |
||
42 | 1 | yield CoInterface::RETURN_WITH => static::syncExec($ch); |
|
43 | } |
||
44 | 10 | yield CoInterface::RETURN_WITH => $response; |
|
45 | // @codeCoverageIgnoreStart |
||
46 | } |
||
47 | // @codeCoverageIgnoreEnd |
||
48 | |||
49 | 13 | public static function syncExecDecoded($ch, $return_response_object = false) |
|
58 | |||
59 | 10 | public static function asyncExecDecoded($ch, $return_response_object = false) |
|
69 | // @codeCoverageIgnoreEnd |
||
70 | } |
||
71 |