Make Url::parseUrl() and Url::percentEncodeChars() static functions.

This commit is contained in:
Zach Borboa
2021-08-06 19:31:33 -04:00
parent 45c09153fc
commit 25e9126f77
2 changed files with 7 additions and 17 deletions
+5 -5
View File
@@ -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';
+2 -12
View File
@@ -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);
}