Created
March 10, 2011 20:57
-
-
Save cbandy/864916 to your computer and use it in GitHub Desktop.
cURL wrapper object
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 | |
/** | |
* Wrapper around PHP's procedural API | |
*/ | |
class Kohana_cURL | |
{ | |
public static function factory(string $url = NULL) | |
{ | |
// Raises E_WARNING upon error | |
$handle = curl_init($url); | |
return $handle ? new Kohana_cURL($handle) : NULL; | |
} | |
protected $_handle; | |
public function __construct(resource $handle) | |
{ | |
$this->_handle = $handle; | |
} | |
public function __destruct() | |
{ | |
curl_close($this->_handle); | |
} | |
public function errno() | |
{ | |
return curl_errno($this->_handle); | |
} | |
public function error() | |
{ | |
return curl_error($this->_handle); | |
} | |
public function exec() | |
{ | |
return curl_exec($this->_handle); | |
} | |
public function getinfo(int $opt = 0) | |
{ | |
return curl_getinfo($this->_handle, $opt); | |
} | |
public function setopt(int $option, mixed $value) | |
{ | |
return curl_setopt($this->_handle, $option, $value); | |
} | |
public function setopt_array(array $options) | |
{ | |
return curl_setopt_array($this->_handle, $options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moved resource creation into a factory method so errors during initialization never create an instance.