mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-25 12:09:11 +00:00
Make $instance->url public; Remove getUrl(), setUrl()
This commit is contained in:
@@ -120,13 +120,11 @@ $curl = new Curl();
|
||||
$curl->setOpt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1');
|
||||
|
||||
$curl->success(function($instance) {
|
||||
$url = $instance->getUrl();
|
||||
echo 'call to "' . $url . '" was successful. response was' . "\n";
|
||||
echo 'call to "' . $instance->url . '" was successful. response was' . "\n";
|
||||
echo $instance->response . "\n";
|
||||
});
|
||||
$curl->error(function($instance) {
|
||||
$url = $instance->getUrl();
|
||||
echo 'call to "' . $url . '" was unsuccessful.' . "\n";
|
||||
echo 'call to "' . $instance->url . '" was unsuccessful.' . "\n";
|
||||
echo 'error code:' . $instance->error_code . "\n";
|
||||
echo 'error message:' . $instance->error_message . "\n";
|
||||
});
|
||||
|
||||
+16
-29
@@ -10,7 +10,6 @@ class Curl
|
||||
private $headers = array();
|
||||
private $options = array();
|
||||
|
||||
private $url = null;
|
||||
private $multi_parent = false;
|
||||
private $multi_child = false;
|
||||
private $before_send_function = null;
|
||||
@@ -33,6 +32,7 @@ class Curl
|
||||
public $http_status_code = 0;
|
||||
public $http_error_message = null;
|
||||
|
||||
public $url = null;
|
||||
public $request_headers = null;
|
||||
public $response_headers = null;
|
||||
public $response = null;
|
||||
@@ -63,9 +63,8 @@ class Curl
|
||||
$curl = new Curl();
|
||||
$curl->multi_child = true;
|
||||
|
||||
$url = $this->buildURL($url, $data);
|
||||
$curl->setUrl($url);
|
||||
$curl->setOpt(CURLOPT_URL, $url, $curl->curl);
|
||||
$curl->url = $this->buildURL($url, $data);
|
||||
$curl->setOpt(CURLOPT_URL, $curl->url, $curl->curl);
|
||||
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
$curl->setOpt(CURLOPT_HTTPGET, true);
|
||||
$this->call($this->before_send_function, $curl);
|
||||
@@ -103,9 +102,8 @@ class Curl
|
||||
$this->exec($ch);
|
||||
}
|
||||
} else {
|
||||
$url = $this->buildURL($url_mixed, $data);
|
||||
$this->setUrl($url);
|
||||
$this->setopt(CURLOPT_URL, $url);
|
||||
$this->url = $this->buildURL($url_mixed, $data);
|
||||
$this->setopt(CURLOPT_URL, $this->url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
$this->setopt(CURLOPT_HTTPGET, true);
|
||||
return $this->exec();
|
||||
@@ -118,8 +116,8 @@ class Curl
|
||||
$this->unsetHeader('Content-Length');
|
||||
}
|
||||
|
||||
$this->setUrl($url);
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($url));
|
||||
$this->url = $url;
|
||||
$this->setOpt(CURLOPT_URL, $this->url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
$this->setOpt(CURLOPT_POST, true);
|
||||
$this->setOpt(CURLOPT_POSTFIELDS, $this->postfields($data));
|
||||
@@ -128,8 +126,8 @@ class Curl
|
||||
|
||||
public function put($url, $data = array())
|
||||
{
|
||||
$this->setUrl($url);
|
||||
$this->setOpt(CURLOPT_URL, $url);
|
||||
$this->url = $url;
|
||||
$this->setOpt(CURLOPT_URL, $this->url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
$put_data = http_build_query($data);
|
||||
if (empty($this->options[CURLOPT_INFILE]) && empty($this->options[CURLOPT_INFILESIZE])) {
|
||||
@@ -141,9 +139,9 @@ class Curl
|
||||
|
||||
public function patch($url, $data = array())
|
||||
{
|
||||
$this->setUrl($url);
|
||||
$this->url = $url;
|
||||
$this->unsetHeader('Content-Length');
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($url));
|
||||
$this->setOpt(CURLOPT_URL, $this->url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PATCH');
|
||||
$this->setOpt(CURLOPT_POSTFIELDS, $data);
|
||||
return $this->exec();
|
||||
@@ -151,18 +149,17 @@ class Curl
|
||||
|
||||
public function delete($url, $data = array())
|
||||
{
|
||||
$this->setUrl($url);
|
||||
$this->url = $url;
|
||||
$this->unsetHeader('Content-Length');
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($url, $data));
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($this->url, $data));
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');
|
||||
return $this->exec();
|
||||
}
|
||||
|
||||
public function head($url, $data = array())
|
||||
{
|
||||
$url = $this->buildURL($url, $data);
|
||||
$this->setUrl($url);
|
||||
$this->setOpt(CURLOPT_URL, $url);
|
||||
$this->url = $this->buildURL($url, $data);
|
||||
$this->setOpt(CURLOPT_URL, $this->url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'HEAD');
|
||||
$this->setOpt(CURLOPT_NOBODY, true);
|
||||
return $this->exec();
|
||||
@@ -171,7 +168,7 @@ class Curl
|
||||
public function options($url, $data = array())
|
||||
{
|
||||
$this->unsetHeader('Content-Length');
|
||||
$this->setUrl($url);
|
||||
$this->url = $url;
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($url, $data));
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS');
|
||||
return $this->exec();
|
||||
@@ -253,16 +250,6 @@ class Curl
|
||||
return $this->options[$option];
|
||||
}
|
||||
|
||||
public function setUrl($url)
|
||||
{
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
public function getUrl()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function verbose($on = true)
|
||||
{
|
||||
$this->setOpt(CURLOPT_VERBOSE, $on);
|
||||
|
||||
@@ -99,37 +99,37 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
// curl -v --get "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'GET', $data);
|
||||
$this->assertEquals(Test::TEST_URL . '?' . http_build_query($data), $test->curl->getUrl());
|
||||
$this->assertEquals(Test::TEST_URL . '?' . http_build_query($data), $test->curl->url);
|
||||
|
||||
// curl -v --request POST "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'POST', $data);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->url);
|
||||
|
||||
// curl -v --request PUT "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'PUT', $data);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->url);
|
||||
|
||||
// curl -v --request PATCH "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'PATCH', $data);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->url);
|
||||
|
||||
// curl -v --request DELETE "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'DELETE', $data);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->url);
|
||||
|
||||
// curl -v --head --get "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'HEAD', $data);
|
||||
$this->assertEquals(Test::TEST_URL . '?' . http_build_query($data), $test->curl->getUrl());
|
||||
$this->assertEquals(Test::TEST_URL . '?' . http_build_query($data), $test->curl->url);
|
||||
|
||||
// curl -v --request OPTIONS "http://127.0.0.1:8000/" -d "foo=bar"
|
||||
$test = new Test();
|
||||
$test->server('server', 'OPTIONS', $data);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->getUrl());
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->url);
|
||||
}
|
||||
|
||||
public function testPostRequestMethod()
|
||||
@@ -792,7 +792,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$curl = $test->curl;
|
||||
$curl->setHeader('X-DEBUG-TEST', 'server');
|
||||
$curl->complete(function ($instance) use ($data) {
|
||||
PHPUnit_Framework_Assert::assertEquals(Test::TEST_URL . '?' . http_build_query($data), $instance->getUrl());
|
||||
PHPUnit_Framework_Assert::assertEquals(Test::TEST_URL . '?' . http_build_query($data), $instance->url);
|
||||
});
|
||||
$curl->get(array(
|
||||
Test::TEST_URL,
|
||||
|
||||
Reference in New Issue
Block a user