1 | <?php |
||
9 | trait RequestorTrait |
||
10 | { |
||
11 | abstract protected function getInternalCurl(); |
||
12 | |||
13 | 5 | public function getAsync($endpoint, array $params = [], $return_response_object = false) |
|
17 | |||
18 | 8 | public function postAsync($endpoint, array $params = [], $return_response_object = false) |
|
22 | |||
23 | 8 | 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 | 6 | public function streamingAsync($endpoint, callable $event_handler, array $params = [], callable $header_response_handler = null) |
|
44 | 6 | { |
|
45 | 6 | $handler = new StreamHandler($header_response_handler, $event_handler); |
|
46 | 6 | $ch = $this->getInternalCurl()->streaming($endpoint, $params, $handler); |
|
47 | try { |
||
48 | 6 | yield $ch; |
|
49 | 5 | } catch (CURLException $e) { |
|
50 | 5 | if (!$handler->isHaltedByUser()) { |
|
51 | 1 | 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) |
|
71 | |||
72 | 1 | public function getOutAsync($endpoint, array $params = [], $return_response_object = false) |
|
76 | |||
77 | 1 | public function postOutAsync($endpoint, array $params = [], $return_response_object = false) |
|
81 | |||
82 | 1 | public function postMultipartOutAsync($endpoint, array $params = [], $return_response_object = false) |
|
86 | |||
87 | 1 | public function getOut($endpoint, array $params = [], $return_response_object = false) |
|
91 | |||
92 | 1 | public function postOut($endpoint, array $params = [], $return_response_object = false) |
|
96 | |||
97 | 1 | public function postMultipartOut($endpoint, array $params = [], $return_response_object = false) |
|
101 | } |
||
102 |