Skip to content

Commit

Permalink
Merge pull request #22 from serzhenko/master
Browse files Browse the repository at this point in the history
added 'PATCH' method support
  • Loading branch information
Phil Sturgeon committed Oct 1, 2013
2 parents db94c52 + 0d9584d commit 9891cb5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 21 additions & 3 deletions libraries/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ function __construct($url = '')

public function __call($method, $arguments)
{
if (in_array($method, array('simple_get', 'simple_post', 'simple_put', 'simple_delete')))
if (in_array($method, array('simple_get', 'simple_post', 'simple_put', 'simple_delete', 'simple_patch')))
{
// Take off the "simple_" and past get/post/put/delete to _simple_call
// Take off the "simple_" and past get/post/put/delete/patch to _simple_call
$verb = str_replace('simple_', '', $method);
array_unshift($arguments, $verb);
return call_user_func_array(array($this, '_simple_call'), $arguments);
Expand Down Expand Up @@ -146,6 +146,24 @@ public function put($params = array(), $options = array())
// Override method, I think this overrides $_POST with PUT data but... we'll see eh?
$this->option(CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: PUT'));
}

public function patch($params = array(), $options = array())
{
// If its an array (instead of a query string) then format it correctly
if (is_array($params))
{
$params = http_build_query($params, NULL, '&');
}

// Add in the specific options provided
$this->options($options);

$this->http_method('patch');
$this->option(CURLOPT_POSTFIELDS, $params);

// Override method, I think this overrides $_POST with PATCH data but... we'll see eh?
$this->option(CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: PATCH'));
}

public function delete($params, $options = array())
{
Expand Down Expand Up @@ -376,4 +394,4 @@ public function set_defaults()
}

/* End of file Curl.php */
/* Location: ./application/libraries/Curl.php */
/* Location: ./application/libraries/Curl.php */
4 changes: 2 additions & 2 deletions spark.info
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name: codeigniter-curl
version: 1.2.1
compatibility: 2.0.0
version: 1.3.0
compatibility: 2.0.0

0 comments on commit 9891cb5

Please sign in to comment.