mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-27 18:50:43 +00:00
Move Curl::buildUrl() to Url::buildUrl()
This commit is contained in:
+2
-24
@@ -4,6 +4,7 @@ namespace Curl;
|
||||
|
||||
use Curl\ArrayUtil;
|
||||
use Curl\Decoder;
|
||||
use Curl\Url;
|
||||
|
||||
class Curl
|
||||
{
|
||||
@@ -1323,7 +1324,7 @@ class Curl
|
||||
*/
|
||||
public function setUrl($url, $mixed_data = '')
|
||||
{
|
||||
$built_url = $this->buildUrl($url, $mixed_data);
|
||||
$built_url = Url::buildUrl($url, $mixed_data);
|
||||
|
||||
if ($this->url === null) {
|
||||
$this->url = (string)new Url($built_url);
|
||||
@@ -1700,29 +1701,6 @@ class Curl
|
||||
}, array_keys($this->cookies), array_values($this->cookies))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Url
|
||||
*
|
||||
* @access private
|
||||
* @param $url
|
||||
* @param $mixed_data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function buildUrl($url, $mixed_data = '')
|
||||
{
|
||||
$query_string = '';
|
||||
if (!empty($mixed_data)) {
|
||||
$query_mark = strpos($url, '?') > 0 ? '&' : '?';
|
||||
if (is_string($mixed_data)) {
|
||||
$query_string .= $query_mark . $mixed_data;
|
||||
} elseif (is_array($mixed_data)) {
|
||||
$query_string .= $query_mark . http_build_query($mixed_data, '', '&');
|
||||
}
|
||||
}
|
||||
return $url . $query_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download Complete
|
||||
*
|
||||
|
||||
@@ -84,6 +84,29 @@ class Url
|
||||
return $output . $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Url
|
||||
*
|
||||
* @access public
|
||||
* @param $url
|
||||
* @param $mixed_data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function buildUrl($url, $mixed_data = '')
|
||||
{
|
||||
$query_string = '';
|
||||
if (!empty($mixed_data)) {
|
||||
$query_mark = strpos($url, '?') > 0 ? '&' : '?';
|
||||
if (is_string($mixed_data)) {
|
||||
$query_string .= $query_mark . $mixed_data;
|
||||
} elseif (is_array($mixed_data)) {
|
||||
$query_string .= $query_mark . http_build_query($mixed_data, '', '&');
|
||||
}
|
||||
}
|
||||
return $url . $query_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Absolutize url.
|
||||
*
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace CurlTest;
|
||||
|
||||
use Curl\CaseInsensitiveArray;
|
||||
use Curl\Curl;
|
||||
use Curl\Url;
|
||||
use Helper\Test;
|
||||
use Helper\User;
|
||||
|
||||
@@ -3418,11 +3419,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
|
||||
),
|
||||
);
|
||||
foreach ($tests as $test) {
|
||||
$curl_1 = new Curl();
|
||||
$reflector = new \ReflectionObject($curl_1);
|
||||
$method = $reflector->getMethod('buildUrl');
|
||||
$method->setAccessible(true);
|
||||
$actual_url = $method->invoke($curl_1, $test['args']['url'], $test['args']['mixed_data']);
|
||||
$actual_url = Url::buildUrl($test['args']['url'], $test['args']['mixed_data']);
|
||||
$this->assertEquals($test['expected'], $actual_url);
|
||||
|
||||
$curl_2 = new Curl();
|
||||
@@ -3445,13 +3442,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
|
||||
ini_set('arg_separator.output', $arg_separator);
|
||||
}
|
||||
|
||||
$curl = new Curl();
|
||||
|
||||
$reflector = new \ReflectionObject($curl);
|
||||
$method = $reflector->getMethod('buildUrl');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$actual_url = $method->invoke($curl, $base_url, $data);
|
||||
$actual_url = Url::buildUrl($base_url, $data);
|
||||
$this->assertEquals($expected_url, $actual_url);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user