Use byjg/uri dependency instead of adding new URL-handling library in PHPRenderer
This commit is contained in:
parent
e082c0535d
commit
b0a258cd0e
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Directory\Utils;
|
||||
|
||||
/**
|
||||
* URL related static utilities
|
||||
*
|
||||
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
||||
* @package Friendica\Directory\Utils
|
||||
*/
|
||||
class Url
|
||||
{
|
||||
/**
|
||||
* Mirror of parse_url function, puts components back together to form a URI.
|
||||
*
|
||||
* @param array $parsed
|
||||
* @return string
|
||||
*/
|
||||
public static function unparse(array $parsed)
|
||||
{
|
||||
$scheme = $parsed['scheme'] ?? null;
|
||||
$user = $parsed['user'] ?? null;
|
||||
$pass = $parsed['pass'] ?? null;
|
||||
$userinfo = $pass !== null ? "$user:$pass" : $user;
|
||||
$port = $parsed['port'] ?? null;
|
||||
$query = $parsed['query'] ?? null;
|
||||
$fragment = $parsed['fragment'] ?? null;
|
||||
$authority = ($userinfo !== null ? $userinfo . "@" : '') .
|
||||
($parsed['host'] ?? '') .
|
||||
($port ? ":$port" : '');
|
||||
|
||||
return (!empty($scheme) ? $scheme . ":" : '') .
|
||||
(strlen($authority) ? "//" . $authority : '') .
|
||||
($parsed['path'] ?? '') .
|
||||
(strlen($query) ? "?" . $query : '') .
|
||||
(strlen($fragment) ? "#" . $fragment : '');
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Friendica\Directory\Views;
|
||||
|
||||
use Friendica\Directory\Utils\Url;
|
||||
use Slim\Router;
|
||||
|
||||
/**
|
||||
|
@ -206,18 +205,9 @@ class PhpRenderer extends \Slim\Views\PhpRenderer
|
|||
function u(string $url)
|
||||
{
|
||||
if ($this->getAttribute('zrl')) {
|
||||
$queryParameters = [];
|
||||
|
||||
$parsed = parse_url($url);
|
||||
if (!empty($parsed['query'])) {
|
||||
parse_str($parsed['query'], $queryParameters);
|
||||
}
|
||||
|
||||
$queryParameters['zrl'] = $this->getAttribute('zrl');
|
||||
|
||||
$parsed['query'] = http_build_query($queryParameters);
|
||||
|
||||
$url = Url::unparse($parsed);
|
||||
$uri = new \ByJG\Util\Uri($url);
|
||||
$uri->withQueryKeyValue('zrl', $this->getAttribute('zrl'));
|
||||
$url = $uri->__toString();
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
|
Loading…
Reference in a new issue