-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleCurl.php
More file actions
71 lines (64 loc) · 1.66 KB
/
SimpleCurl.php
File metadata and controls
71 lines (64 loc) · 1.66 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
<?php
/**
* Class SimpleCurl
* @url https://bitbucket.org/engrsayedahmd/simplecurl/src/master/
*/
class SimpleCurl
{
protected static $url;
protected static $headers;
protected static $query;
protected static $response;
/**
* @param $url
* @param array $headers
* @param $query
*/
public static function prepare($url, $query, array $headers = [])
{
self::$url = $url;
self::$headers = $headers;
self::$query = http_build_query($query);
}
/**
* Execute post method curl request
*/
public static function post()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, self::$url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, self::$headers);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, self::$query);
self::$response = curl_exec($curl);
curl_close($curl);
}
/**
* Execute get method curl request
*/
public static function get()
{
$url = self::$url . '?' . self::$query;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, self::$headers);
self::$response = curl_exec($curl);
curl_close($curl);
}
/**
* @return mixed
*/
public static function getResponse()
{
return self::$response;
}
/**
* @return mixed
*/
public static function getResponseAssoc()
{
return json_decode(self::$response, true);
}
}