mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 04:01:47 +00:00
Make Url::parseUrl() and Url::percentEncodeChars() static functions.
This commit is contained in:
+5
-5
@@ -114,14 +114,14 @@ class Url
|
||||
*/
|
||||
private function absolutizeUrl()
|
||||
{
|
||||
$b = $this->parseUrl($this->baseUrl);
|
||||
$b = self::parseUrl($this->baseUrl);
|
||||
if (!isset($b['path'])) {
|
||||
$b['path'] = '/';
|
||||
}
|
||||
if ($this->relativeUrl === null) {
|
||||
return $this->unparseUrl($b);
|
||||
}
|
||||
$r = $this->parseUrl($this->relativeUrl);
|
||||
$r = self::parseUrl($this->relativeUrl);
|
||||
$r['authorized'] = isset($r['scheme']) || isset($r['host']) || isset($r['port'])
|
||||
|| isset($r['user']) || isset($r['pass']);
|
||||
$target = [];
|
||||
@@ -178,7 +178,7 @@ class Url
|
||||
*
|
||||
* Parse url into components of a URI as specified by RFC 3986.
|
||||
*/
|
||||
private function parseUrl($url)
|
||||
public static function parseUrl($url)
|
||||
{
|
||||
// RFC 3986 - Parsing a URI Reference with a Regular Expression.
|
||||
// ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
|
||||
@@ -223,7 +223,7 @@ class Url
|
||||
}
|
||||
}
|
||||
if (isset($output_array['5']) && $output_array['5'] !== '') {
|
||||
$parts['path'] = $this->percentEncodeChars($output_array['5']);
|
||||
$parts['path'] = self::percentEncodeChars($output_array['5']);
|
||||
}
|
||||
if (isset($output_array['7']) && $output_array['7'] !== '') {
|
||||
$parts['query'] = $output_array['7'];
|
||||
@@ -240,7 +240,7 @@ class Url
|
||||
* Percent-encode characters to represent a data octet in a component when
|
||||
* that octet's corresponding character is outside the allowed set.
|
||||
*/
|
||||
private function percentEncodeChars($chars)
|
||||
private static function percentEncodeChars($chars)
|
||||
{
|
||||
// ALPHA = A-Z / a-z
|
||||
$alpha = 'A-Za-z';
|
||||
|
||||
@@ -98,12 +98,7 @@ class UrlTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->assertEquals($expected_parts, parse_url($input_url));
|
||||
|
||||
$reflector = new \ReflectionClass('Curl\Url');
|
||||
$reflection_method = $reflector->getMethod('parseUrl');
|
||||
$reflection_method->setAccessible(true);
|
||||
|
||||
$url = new Url(null);
|
||||
$result = $reflection_method->invoke($url, $input_url);
|
||||
$result = Url::parseUrl($input_url);
|
||||
$this->assertEquals($expected_parts, $result);
|
||||
}
|
||||
|
||||
@@ -123,12 +118,7 @@ class UrlTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->assertEquals($expected_parts, parse_url($input_url));
|
||||
|
||||
$reflector = new \ReflectionClass('Curl\Url');
|
||||
$reflection_method = $reflector->getMethod('parseUrl');
|
||||
$reflection_method->setAccessible(true);
|
||||
|
||||
$url = new Url(null);
|
||||
$result = $reflection_method->invoke($url, $input_url);
|
||||
$result = Url::parseUrl($input_url);
|
||||
$this->assertEquals($expected_parts, $result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user