-
-
Save r37r0m0d3l/5734637 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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