1 | <?php |
||
13 | class CurlAdapter implements HttpInterface |
||
14 | { |
||
15 | /** |
||
16 | * Contains the curl instance. |
||
17 | * |
||
18 | * @var resource |
||
19 | */ |
||
20 | private $curl; |
||
21 | |||
22 | /** |
||
23 | * Executes curl request. |
||
24 | * |
||
25 | * @param string $url |
||
26 | * @param array $options |
||
27 | * |
||
28 | * @return string |
||
29 | */ |
||
30 | public function execute($url, array $options = []) |
||
31 | { |
||
32 | $this->init($url)->setOptions($options); |
||
33 | $res = curl_exec($this->curl); |
||
34 | $this->close(); |
||
35 | |||
36 | return $res; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Initializes curl resource. |
||
41 | * |
||
42 | * @param string $url |
||
43 | * |
||
44 | * @return $this |
||
45 | */ |
||
46 | protected function init($url) |
||
52 | |||
53 | /** |
||
54 | * Sets multiple options at the same time. |
||
55 | * |
||
56 | * @param array $options |
||
57 | * |
||
58 | * @return static |
||
59 | */ |
||
60 | protected function setOptions(array $options = []) |
||
66 | |||
67 | /** |
||
68 | * Get curl errors. |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getErrors() |
||
76 | |||
77 | /** |
||
78 | * Close the curl resource. |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | protected function close() |
||
86 | } |
||
87 |