Skip to content

Commit

Permalink
Merge pull request #26 from MikeLund/master
Browse files Browse the repository at this point in the history
Change "setopt" to camelCase (#25)
  • Loading branch information
amouhzi authored Aug 13, 2016
2 parents cc486a8 + c0abc85 commit 36594a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ var_dump($curl->response_headers);

```php
$curl = new Curl\Curl();
$curl->setopt(CURLOPT_RETURNTRANSFER, TRUE);
$curl->setopt(CURLOPT_SSL_VERIFYPEER, FALSE);
$curl->setOpt(CURLOPT_RETURNTRANSFER, TRUE);
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
$curl->get('https://encrypted.example.com/');
```

Expand Down
48 changes: 24 additions & 24 deletions src/Curl/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ public function __construct()
public function get($url, $data = array())
{
if (count($data) > 0) {
$this->setopt(CURLOPT_URL, $url . '?' . http_build_query($data));
$this->setOpt(CURLOPT_URL, $url . '?' . http_build_query($data));
} else {
$this->setopt(CURLOPT_URL, $url);
$this->setOpt(CURLOPT_URL, $url);
}
$this->setopt(CURLOPT_HTTPGET, true);
$this->setOpt(CURLOPT_HTTPGET, true);
$this->_exec();
}

public function post($url, $data = array())
{
$this->setopt(CURLOPT_URL, $url);
$this->setopt(CURLOPT_POST, true);
$this->setOpt(CURLOPT_URL, $url);
$this->setOpt(CURLOPT_POST, true);
if (is_array($data) || is_object($data))
{
$data = http_build_query($data);
}
$this->setopt(CURLOPT_POSTFIELDS, $data);
$this->setOpt(CURLOPT_POSTFIELDS, $data);
$this->_exec();
}

Expand All @@ -75,39 +75,39 @@ public function put($url, $data = array(), $json = 0)
if ($json == 0) {
$url .= '?' . http_build_query($data);
} else {
$this->setopt(CURLOPT_POST, true);
$this->setOpt(CURLOPT_POST, true);

if (is_array($data) || is_object($data)) {
$data = http_build_query($data);
}

$this->setopt(CURLOPT_POSTFIELDS, $data);
$this->setOpt(CURLOPT_POSTFIELDS, $data);
}

$this->setopt(CURLOPT_URL, $url);
$this->setopt(CURLOPT_CUSTOMREQUEST, 'PUT');
$this->setOpt(CURLOPT_URL, $url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT');
$this->_exec();
}

public function patch($url, $data = array())
{
$this->setopt(CURLOPT_URL, $url);
$this->setopt(CURLOPT_CUSTOMREQUEST, 'PATCH');
$this->setopt(CURLOPT_POSTFIELDS, $data);
$this->setOpt(CURLOPT_URL, $url);
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
$this->setOpt(CURLOPT_POSTFIELDS, $data);
$this->_exec();
}

public function delete($url, $data = array())
{
$this->setopt(CURLOPT_URL, $url . '?' . http_build_query($data));
$this->setopt(CURLOPT_CUSTOMREQUEST, 'DELETE');
$this->setOpt(CURLOPT_URL, $url . '?' . http_build_query($data));
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
$this->_exec();
}

public function setBasicAuthentication($username, $password)
{
$this->setHttpAuth(self::AUTH_BASIC);
$this->setopt(CURLOPT_USERPWD, $username . ':' . $password);
$this->setOpt(CURLOPT_USERPWD, $username . ':' . $password);
}

protected function setHttpAuth($httpauth)
Expand All @@ -118,23 +118,23 @@ protected function setHttpAuth($httpauth)
public function setHeader($key, $value)
{
$this->_headers[$key] = $key . ': ' . $value;
$this->setopt(CURLOPT_HTTPHEADER, array_values($this->_headers));
$this->setOpt(CURLOPT_HTTPHEADER, array_values($this->_headers));
}

public function setUserAgent($user_agent)
{
$this->setopt(CURLOPT_USERAGENT, $user_agent);
$this->setOpt(CURLOPT_USERAGENT, $user_agent);
}

public function setReferrer($referrer)
{
$this->setopt(CURLOPT_REFERER, $referrer);
$this->setOpt(CURLOPT_REFERER, $referrer);
}

public function setCookie($key, $value)
{
$this->_cookies[$key] = $value;
$this->setopt(CURLOPT_COOKIE, http_build_query($this->_cookies, '', '; '));
$this->setOpt(CURLOPT_COOKIE, http_build_query($this->_cookies, '', '; '));
}

public function setOpt($option, $value)
Expand All @@ -144,7 +144,7 @@ public function setOpt($option, $value)

public function verbose($on = true)
{
$this->setopt(CURLOPT_VERBOSE, $on);
$this->setOpt(CURLOPT_VERBOSE, $on);
}

public function close()
Expand Down Expand Up @@ -210,8 +210,8 @@ private function init()
{
$this->curl = curl_init();
$this->setUserAgent(self::USER_AGENT);
$this->setopt(CURLINFO_HEADER_OUT, true);
$this->setopt(CURLOPT_HEADER, true);
$this->setopt(CURLOPT_RETURNTRANSFER, true);
$this->setOpt(CURLINFO_HEADER_OUT, true);
$this->setOpt(CURLOPT_HEADER, true);
$this->setOpt(CURLOPT_RETURNTRANSFER, true);
}
}
6 changes: 3 additions & 3 deletions tests/CurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public function testPutFileHandle() {
$png = $this->create_png();
$tmp_file = $this->create_tmp_file($png);

$this->curl->setopt(CURLOPT_PUT, TRUE);
$this->curl->setopt(CURLOPT_INFILE, $tmp_file);
$this->curl->setopt(CURLOPT_INFILESIZE, strlen($png));
$this->curl->setOpt(CURLOPT_PUT, TRUE);
$this->curl->setOpt(CURLOPT_INFILE, $tmp_file);
$this->curl->setOpt(CURLOPT_INFILESIZE, strlen($png));
$this->curl->put(self::TEST_URL . '/server.php', array(
'test' => 'put_file_handle',
));
Expand Down

0 comments on commit 36594a2

Please sign in to comment.