diff --git a/composer.json b/composer.json index 277fbb1..986d0c5 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": ">=5.3.0", + "php": ">=5.4.0", "lib-curl": "*" }, "suggest": { diff --git a/dHttp/Client.php b/dHttp/Client.php index 7fe6d53..54e28e1 100644 --- a/dHttp/Client.php +++ b/dHttp/Client.php @@ -17,7 +17,7 @@ class Client CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => false, CURLOPT_SSL_VERIFYPEER => false, - CURLOPT_USERAGENT => 'dHttp' + CURLOPT_USERAGENT => 'PHP dHttp/Client 1.3' ]; /** * @var array @@ -57,7 +57,7 @@ public function __construct($url = null, array $options = []) public function setUrl($url) { if ($url !== null) { - $this->_options[CURLOPT_URL] = Url::validateUrl($url); + $this->_options[CURLOPT_URL] = $this->prepareUrl($url); } return $this; @@ -176,7 +176,10 @@ public function addOptions(array $params) */ public function post($fields = [], array $options = []) { - return $this->get($options + [CURLOPT_POST => true, CURLOPT_POSTFIELDS => is_array($fields) ? http_build_query($fields) : $fields]); + return $this->get($options + [ + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => is_array($fields) ? http_build_query($fields) : $fields + ]); } /** @@ -188,7 +191,10 @@ public function post($fields = [], array $options = []) */ public function put($fields = [], array $options = []) { - return $this->get($options + [CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => is_array($fields) ? http_build_query($fields) : $fields]); + return $this->get($options + [ + CURLOPT_CUSTOMREQUEST => 'PUT', + CURLOPT_POSTFIELDS => is_array($fields) ? http_build_query($fields) : $fields + ]); } /** @@ -324,6 +330,25 @@ public function reset() return $this; } + /** + * @param $url + * @return string + */ + public function prepareUrl($url) + { + if (is_array($url) && count($url)) { + $newUrl = $url[0]; + + if (isset($url[1]) && is_array($url[1])) { + $newUrl = '?' . http_build_query($url[1]); + } + } else { + $newUrl = $url; + } + + return $newUrl; + } + /** * Return curl information * diff --git a/dHttp/Url.php b/dHttp/Url.php deleted file mode 100644 index 9fea6b3..0000000 --- a/dHttp/Url.php +++ /dev/null @@ -1,62 +0,0 @@ - 'value1' +]], [CURLOPT_TIMEOUT => 5]); $resp = $client->get(); // Get response code @@ -48,7 +51,7 @@ var_dump($resp->getHeader('Content-Type')); required __DIR__ . '/vendor/autoload.php'; $client = new dHttp\Client('http://website.com'); -$client->addOptions(array(CURLOPT_RETURNTRANSFER => false)) +$client->addOptions([CURLOPT_RETURNTRANSFER => false]) ->setCookie('/tmp/cookie.txt') ->setUserAgent('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31') ->post(array(