Skip to content

Commit c42cf17

Browse files
committed
Add put()/delete() methods ti Curl class
1 parent 4e9dbbd commit c42cf17

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/Http/Curl.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function post(
2727
$request = $this->prepareRequest($url, $urlParameters, $headers);
2828

2929
curl_setopt($request, CURLOPT_POST, count($postParameters));
30+
3031
if ($asJSON === true) {
3132
curl_setopt($request, CURLOPT_POSTFIELDS, json_encode($postParameters));
3233
} else {
@@ -52,6 +53,53 @@ public function get($url, array $urlParameters = [], array $headers = [], $asJSO
5253
return $this->executeRequest($request);
5354
}
5455

56+
/**
57+
* Send a put request to a URL
58+
*
59+
* @param string $url
60+
* @param array $urlParameters
61+
* @param array $headers
62+
* @param bool $asJSON
63+
* @return void
64+
*/
65+
public function put(
66+
$url,
67+
array $urlParameters = [],
68+
array $postParameters = [],
69+
array $headers = [],
70+
$asJSON = false
71+
) {
72+
$request = $this->prepareRequest($url, $urlParameters, $headers);
73+
74+
curl_setopt($request, CURLOPT_PUT, true);
75+
76+
if ($asJSON === true) {
77+
curl_setopt($request, CURLOPT_POSTFIELDS, json_encode($postParameters));
78+
} else {
79+
curl_setopt($request, CURLOPT_POSTFIELDS, http_build_query($postParameters));
80+
}
81+
82+
return $this->executeRequest($request);
83+
}
84+
85+
/**
86+
* Send a delete request to a URL.
87+
*
88+
* @param string $url
89+
* @param array $urlParameters
90+
* @param array $headers
91+
* @param bool $asJSON
92+
* @return Response
93+
*/
94+
public function delete($url, array $urlParameters = [], array $headers = [], $asJSON = false)
95+
{
96+
$request = $this->prepareRequest($url, $urlParameters, $headers);
97+
98+
curl_setopt($request, CURLOPT_CUSTOMREQUEST, 'DELETE');
99+
100+
return $this->executeRequest($request);
101+
}
102+
55103
/**
56104
* Prepares a request using curl.
57105
*

0 commit comments

Comments
 (0)