forked from klarna/php-xmlrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurlHandle.php
More file actions
108 lines (100 loc) · 2.02 KB
/
CurlHandle.php
File metadata and controls
108 lines (100 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* File containing the CurlHandle class.
*
* PHP version 5.3
*
* @category Payment
* @package KlarnaAPI
* @author MINT <ms.modules@klarna.com>
* @copyright 2014 Klarna AB
* @license http://opensource.org/licenses/BSD-2-Clause BSD-2
* @link https://developers.klarna.com/
*/
/**
* CurlHandle
*
* @category Payment
* @package KlarnaAPI
* @author MINT <ms.modules@klarna.com>
* @copyright 2014 Klarna AB
* @license http://opensource.org/licenses/BSD-2-Clause BSD-2
* @link https://developers.klarna.com/
*/
class CurlHandle
{
/**
* @var cURL
*/
protected $handle;
/**
* Constructor
*
* @throws RuntimeException if cURL extension is not loaded
*/
public function __construct()
{
if (!extension_loaded('curl')) {
throw new RuntimeException(
'cURL extension is requred.'
);
}
}
/**
* Initialize the handle
*
* @return void
*/
public function init()
{
$this->handle = curl_init();
}
/**
* Set a cURL option
*
* @param int $name CURLOPT_* constant
* @param mixed $value Option value
*
* @return void
*/
public function setOption($name, $value)
{
curl_setopt($this->handle, $name, $value);
}
/**
* Execute cURL handle
*
* @return void
*/
public function execute()
{
return curl_exec($this->handle);
}
/**
* Get cURL info
*
* @return array|false Array with info or false if error occurred
*/
public function getInfo()
{
return curl_getinfo($this->handle);
}
/**
* Get cURL error
*
* @return string|false Error message or false if no error occurred
*/
public function getError()
{
return curl_error($this->handle);
}
/**
* Close the cURL handle
*
* @return void
*/
public function close()
{
curl_close($this->handle);
}
}