From 8f5d10aa47876f14f9b5208de1fabe54657da359 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Wed, 9 Jun 2021 23:27:49 -0400 Subject: [PATCH] Move Curl::buildUrl() to Url::buildUrl() --- src/Curl/Curl.php | 26 ++----------------------- src/Curl/Url.php | 23 ++++++++++++++++++++++ tests/PHPCurlClass/PHPCurlClassTest.php | 15 +++----------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index eb30ce6..5d26375 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -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 * diff --git a/src/Curl/Url.php b/src/Curl/Url.php index 866903c..4b47c3c 100644 --- a/src/Curl/Url.php +++ b/src/Curl/Url.php @@ -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. * diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 9090f4f..4fc1ddf 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -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); } }