Skip to content

Instantly share code, notes, and snippets.

@r37r0m0d3l
Forked from lastguest/cURL.class.php
Created June 8, 2013 09:20
Show Gist options
  • Save r37r0m0d3l/5734637 to your computer and use it in GitHub Desktop.
Save r37r0m0d3l/5734637 to your computer and use it in GitHub Desktop.
<?php
/**
* cURL Object Oriented API
* @author Stefano Azzolini <[email protected]>
*/
class cURL {
/**
* The cURL resource descriptor
* @var Resource
*/
private $curl = null;
/**
* Call curl_init and store the resource internally.
* @param string $url The URL (default:null)
*/
public function __construct($url = null){
return $this->init($url);
}
/**
* Magic Metjod for proxying calls for this class to curl_* procedurals
* @param string $n Function name
* @param array $p Call parametrs
* @return mixed The called function return value
*/
public function __call($n,$p){
if($n=='init' || $n=='multi_init'){
// Close the connection if it was opened.
if($this->curl) curl_close($this->curl);
// Save the resource internally
return $this->curl = call_user_func_array('curl_'.$n,$p);
} else {
// Inject the current resource to the function call
array_unshift($p,$this->curl);
return call_user_func_array('curl_'.$n,$p);
}
}
}
/*
* Example
*/
$http = new CURL("http://graph.facebook.com/CaffeinaLab");
$http->setopt(CURLOPT_HEADER, 0);
$http->setopt(CURLOPT_RETURNTRANSFER, 1);
echo $http->exec();
$http->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment