From ce754fa465c7b1149689495b661a425071c775f6 Mon Sep 17 00:00:00 2001 From: moehm Date: Thu, 4 Dec 2014 13:39:03 +0100 Subject: Added php class simpleCurlWrapper (unfinished) --- php/simpleCurlWrapper.php | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 php/simpleCurlWrapper.php (limited to 'php/simpleCurlWrapper.php') diff --git a/php/simpleCurlWrapper.php b/php/simpleCurlWrapper.php new file mode 100644 index 0000000..b15a56c --- /dev/null +++ b/php/simpleCurlWrapper.php @@ -0,0 +1,80 @@ +init($url, $options); + } + + public function init($url = false, $options = array(), $exec = false){ + if( ! $url ){ + return false; + } + + $this->ch = curl_init( $url ); + $this->setOptions( $options ); + + if ( $exec ){ + $this->exec(); + } + } + + public function setOption($param = false, $value = false){ + if ( ! $param && ! $value ){ + return; + } + curl_setopt($this->ch, $param, $value); + } + + public function setOptions( $options = array() ){ + if ( ! empty( $options ) ){ + foreach( $options as $key => $value ){ + $this->setOption($key, $value); + } + } + } + + public function exec(){ + $this->result = curl_exec( $this->ch ); + } + + public function getInfo($param){ + return curl_getinfo($this->ch, $param); + } + + public function setRequestMethod( $string ){ + $request = strtolower( $string ); + switch( $string ){ + case("head"): + break; + case("post"): + break; + case("get"): + break; + case("put"): + break; + case("delete"): + break; + default: + return false; + } + } + + public function setUserAgent($string){ + return curl_setopt( $this->ch, CURLOPT_USERAGENT, $string ); + } + + public function getStatusCode(){ + return curl_getinfo( $this->ch, CURLOPT_HTTPHEADER); + } + + public function __destruct(){ + curl_close( $this->ch ); + } +} -- cgit v1.2.3