1 | <?php |
||
9 | trait RequestorTrait |
||
10 | { |
||
11 | abstract protected function getInternalCurl(); |
||
12 | |||
13 | 1 | public function getAsync($endpoint, array $params = [], $return_response_object = false) |
|
17 | |||
18 | 1 | public function postAsync($endpoint, array $params = [], $return_response_object = false) |
|
22 | |||
23 | 1 | public function postMultipartAsync($endpoint, array $params = [], $return_response_object = false) |
|
27 | |||
28 | 6 | public function get($endpoint, array $params = [], $return_response_object = false) |
|
32 | |||
33 | 5 | public function post($endpoint, array $params = [], $return_response_object = false) |
|
37 | |||
38 | 1 | public function postMultipart($endpoint, array $params = [], $return_response_object = false) |
|
42 | |||
43 | 5 | public function streamingAsync($endpoint, callable $event_handler, array $params = [], callable $header_response_handler = null) |
|
44 | 5 | { |
|
45 | 5 | $handler = new StreamHandler($header_response_handler, $event_handler); |
|
46 | 5 | $ch = $this->getInternalCurl()->streaming($endpoint, $params, $handler); |
|
47 | try { |
||
48 | 5 | yield $ch; |
|
49 | 4 | } catch (CURLException $e) { |
|
50 | 4 | if (!$handler->isHaltedByUser()) { |
|
51 | throw $e; |
||
52 | } |
||
53 | } |
||
54 | 5 | if (!$handler->isHaltedByUser()) { |
|
55 | 1 | throw new \UnexpectedValueException('Streaming stopped unexpectedly.'); |
|
56 | } |
||
57 | 4 | } |
|
58 | |||
59 | 6 | public function streaming($endpoint, callable $event_handler, array $params = [], callable $header_response_handler = null) |
|
60 | 6 | { |
|
61 | 6 | $handler = new StreamHandler($header_response_handler, $event_handler); |
|
62 | 6 | $ch = $this->getInternalCurl()->streaming($endpoint, $params, $handler); |
|
63 | 6 | $result = curl_exec($ch); |
|
64 | 4 | if (!$handler->isHaltedByUser() && $result === false) { |
|
65 | 1 | throw new CURLException(curl_error($ch), curl_errno($ch), $ch); |
|
66 | } |
||
67 | 3 | if (!$handler->isHaltedByUser()) { |
|
68 | 1 | throw new \UnexpectedValueException('Streaming stopped unexpectedly.'); |
|
69 | } |
||
70 | 2 | } |
|
71 | |||
72 | public function getOutAsync($endpoint, array $params = [], $return_response_object = false) |
||
76 | |||
77 | public function postOutAsync($endpoint, array $params = [], $return_response_object = false) |
||
81 | |||
82 | public function postMultipartOutAsync($endpoint, array $params = [], $return_response_object = false) |
||
86 | |||
87 | public function getOut($endpoint, array $params = [], $return_response_object = false) |
||
91 | |||
92 | public function postOut($endpoint, array $params = [], $return_response_object = false) |
||
96 | |||
97 | public function postMultipartOut($endpoint, array $params = [], $return_response_object = false) |
||
101 | } |
||
102 |