1
0
Fork 0
mirror of synced 2024-05-20 04:32:37 +12:00

fixed PSR issues in the URL library

This commit is contained in:
oovk 2021-10-09 19:51:21 +02:00
parent 6c2257e3e8
commit f138aeb3a6

View file

@ -13,7 +13,7 @@ class URL
*
* @return array
*/
public static function parse(string $url):array
public static function parse(string $url): array
{
$default = [
'scheme' => '',
@ -28,7 +28,7 @@ class URL
return \array_merge($default, \parse_url($url));
}
/**
* Un-Parse URL
*
@ -39,32 +39,32 @@ class URL
*
* @return string
*/
public static function unparse(array $url, array $ommit = []):string
public static function unparse(array $url, array $ommit = []): string
{
if (isset($url['path']) && \mb_substr($url['path'], 0, 1) !== '/') {
$url['path'] = '/'.$url['path'];
}
$parts = [];
$parts['scheme'] = isset($url['scheme']) ? $url['scheme'].'://' : '';
$parts['host'] = isset($url['host']) ? $url['host'] : '';
$parts['port'] = isset($url['port']) ? ':'.$url['port'] : '';
$parts['user'] = isset($url['user']) ? $url['user'] : '';
$parts['pass'] = isset($url['pass']) ? ':'.$url['pass'] : '';
$parts['pass'] = isset($url['pass']) ? ':'.$url['pass'] : '';
$parts['pass'] = ($parts['user'] || $parts['pass']) ? $parts['pass'].'@' : '';
$parts['path'] = isset($url['path']) ? $url['path'] : '';
$parts['query'] = isset($url['query']) && !empty($url['query']) ? '?'.$url['query'] : '';
$parts['fragment'] = isset($url['fragment']) ? '#'.$url['fragment'] : '';
if ($ommit) {
foreach ($ommit as $key) {
if (isset($parts[ $key ])) {
@ -72,7 +72,7 @@ class URL
}
}
}
return $parts['scheme'].$parts['user'].$parts['pass'].$parts['host'].$parts['port'].$parts['path'].$parts['query'].$parts['fragment'];
}
@ -85,7 +85,7 @@ class URL
*
* @return array
*/
public static function parseQuery(string $query):array
public static function parseQuery(string $query): array
{
\parse_str($query, $result);
@ -101,7 +101,7 @@ class URL
*
* @return string
*/
public static function unparseQuery(array $query):string
public static function unparseQuery(array $query): string
{
return \http_build_query($query);
}