mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-05 23:38:22 +00:00
Add base url property
This commit is contained in:
@@ -32,6 +32,7 @@ class Curl
|
||||
public $http_status_code = 0;
|
||||
public $http_error_message = null;
|
||||
|
||||
public $base_url = null;
|
||||
public $url = null;
|
||||
public $request_headers = null;
|
||||
public $response_headers = null;
|
||||
@@ -63,6 +64,7 @@ class Curl
|
||||
$curl = new Curl();
|
||||
$curl->multi_child = true;
|
||||
|
||||
$curl->base_url = $url;
|
||||
$curl->url = $this->buildURL($url, $data);
|
||||
$curl->setOpt(CURLOPT_URL, $curl->url, $curl->curl);
|
||||
$curl->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
@@ -102,6 +104,7 @@ class Curl
|
||||
$this->exec($ch);
|
||||
}
|
||||
} else {
|
||||
$this->base_url = $url_mixed;
|
||||
$this->url = $this->buildURL($url_mixed, $data);
|
||||
$this->setopt(CURLOPT_URL, $this->url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
@@ -116,6 +119,7 @@ class Curl
|
||||
$this->unsetHeader('Content-Length');
|
||||
}
|
||||
|
||||
$this->base_url = $url;
|
||||
$this->url = $url;
|
||||
$this->setOpt(CURLOPT_URL, $this->url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
@@ -126,6 +130,7 @@ class Curl
|
||||
|
||||
public function put($url, $data = array())
|
||||
{
|
||||
$this->base_url = $url;
|
||||
$this->url = $url;
|
||||
$this->setOpt(CURLOPT_URL, $this->url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT');
|
||||
@@ -139,6 +144,7 @@ class Curl
|
||||
|
||||
public function patch($url, $data = array())
|
||||
{
|
||||
$this->base_url = $url;
|
||||
$this->url = $url;
|
||||
$this->unsetHeader('Content-Length');
|
||||
$this->setOpt(CURLOPT_URL, $this->url);
|
||||
@@ -149,6 +155,7 @@ class Curl
|
||||
|
||||
public function delete($url, $data = array())
|
||||
{
|
||||
$this->base_url = $url;
|
||||
$this->url = $url;
|
||||
$this->unsetHeader('Content-Length');
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($this->url, $data));
|
||||
@@ -158,6 +165,7 @@ class Curl
|
||||
|
||||
public function head($url, $data = array())
|
||||
{
|
||||
$this->base_url = $url;
|
||||
$this->url = $this->buildURL($url, $data);
|
||||
$this->setOpt(CURLOPT_URL, $this->url);
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'HEAD');
|
||||
@@ -168,6 +176,7 @@ class Curl
|
||||
public function options($url, $data = array())
|
||||
{
|
||||
$this->unsetHeader('Content-Length');
|
||||
$this->base_url = $url;
|
||||
$this->url = $url;
|
||||
$this->setOpt(CURLOPT_URL, $this->buildURL($url, $data));
|
||||
$this->setOpt(CURLOPT_CUSTOMREQUEST, 'OPTIONS');
|
||||
|
||||
@@ -92,43 +92,50 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
)));
|
||||
}
|
||||
|
||||
public function testGetUrl()
|
||||
public function testUrl()
|
||||
{
|
||||
$data = array('foo' => 'bar');
|
||||
|
||||
// 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, $test->curl->base_url);
|
||||
$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->base_url);
|
||||
$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->base_url);
|
||||
$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->base_url);
|
||||
$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->base_url);
|
||||
$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, $test->curl->base_url);
|
||||
$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->base_url);
|
||||
$this->assertEquals(Test::TEST_URL, $test->curl->url);
|
||||
}
|
||||
|
||||
@@ -784,7 +791,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
));
|
||||
}
|
||||
|
||||
public function testParallelGetUrl()
|
||||
public function testParallelUrl()
|
||||
{
|
||||
$data = array('foo' => 'bar');
|
||||
|
||||
@@ -792,6 +799,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, $instance->base_url);
|
||||
PHPUnit_Framework_Assert::assertEquals(Test::TEST_URL . '?' . http_build_query($data), $instance->url);
|
||||
});
|
||||
$curl->get(array(
|
||||
|
||||
Reference in New Issue
Block a user