diff options
| author | moehm | 2014-12-04 13:39:03 +0100 |
|---|---|---|
| committer | moehm | 2014-12-04 13:39:03 +0100 |
| commit | ce754fa465c7b1149689495b661a425071c775f6 (patch) | |
| tree | af69cb5939df6f24e25bb719efa65b37471d3dcd /php | |
| parent | 5238c8e35b7f84cbada81214151f61921d41a8ba (diff) | |
| download | dotfiles-ce754fa465c7b1149689495b661a425071c775f6.tar.gz | |
Added php class simpleCurlWrapper (unfinished)
Diffstat (limited to 'php')
| -rw-r--r-- | php/simpleCurlWrapper.php | 80 |
1 files changed, 80 insertions, 0 deletions
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 @@ +<?php + +class simpleCurlWrapper { + + private $ch; + public $result; + + public function __construct($url = false, $options = array()){ + if( ! $url ){ + return; + } + $this->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 ); + } +} |
