"Network::unparseURL" is replaced with "Uri::fromParts"

This commit is contained in:
Michael 2024-05-14 21:47:57 +00:00
parent a6f3c961dc
commit 1c66d49599
9 changed files with 17 additions and 49 deletions

View file

@ -23,8 +23,8 @@ namespace Friendica\Content;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use GuzzleHttp\Psr7\Uri;
/**
* This pager should be used by lists using the min_id†/max_id† parameters
@ -67,7 +67,7 @@ class BoundariesPager extends Pager
$parsed['query'] = http_build_query($queryParameters);
$url = Network::unparseURL($parsed);
$url = (string)Uri::fromParts((array)$parsed);
$this->setQueryString($url);
}

View file

@ -25,8 +25,8 @@ use Friendica\Core\Hook;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use GuzzleHttp\Psr7\Uri;
/**
* ContactSelector class
@ -102,7 +102,7 @@ class ContactSelector
// Create the server url out of the profile url
$parts = parse_url($profile);
unset($parts['path']);
$server_url = Strings::normaliseLink(Network::unparseURL($parts));
$server_url = Strings::normaliseLink((string)Uri::fromParts((array)$parts));
}
self::$server_url[$profile] = $server_url;

View file

@ -29,9 +29,9 @@ use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\XML;
use GuzzleHttp\Psr7\Uri;
use League\HTMLToMarkdown\HtmlConverter;
use Psr\Http\Message\UriInterface;
@ -407,7 +407,7 @@ class HTML
}
$parts = array_merge($base, parse_url($url));
$url2 = Network::unparseURL($parts);
$url2 = (string)Uri::fromParts((array)$parts);
return str_replace($url, $url2, $link);
}

View file

@ -25,7 +25,7 @@ use Friendica\Core\Logger;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use GuzzleHttp\Psr7\Uri;
class PushSubscriber
{
@ -179,7 +179,7 @@ class PushSubscriber
$parts = parse_url($subscriber['callback_url']);
unset($parts['path']);
$server_url = Network::unparseURL($parts);
$server_url = (string)Uri::fromParts((array)$parts);
$gsid = GServer::getID($server_url, true);
if (!empty($gsid)) {
GServer::setProtocol($gsid, Post\DeliveryData::OSTATUS);

View file

@ -26,7 +26,7 @@ use Friendica\Database\DBA;
use Friendica\Model\GServer;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
use Friendica\Util\Network;
use GuzzleHttp\Psr7\Uri;
/**
* Undocumented API endpoint that is implemented by both Mastodon and Pleroma
@ -47,7 +47,7 @@ class Peers extends BaseApi
while ($instance = DBA::fetch($instances)) {
$urldata = parse_url($instance['url']);
unset($urldata['scheme']);
$return[] = ltrim(Network::unparseURL($urldata), '/');
$return[] = ltrim((string)Uri::fromParts((array)$urldata), '/');
}
DBA::close($instances);

View file

@ -33,6 +33,7 @@ use GuzzleHttp\Client;
use GuzzleHttp\Cookie\FileCookieJar;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
use GuzzleHttp\Psr7\Uri;
use GuzzleHttp\RequestOptions;
use mattwright\URLResolver;
use Psr\Http\Message\ResponseInterface;
@ -104,7 +105,7 @@ class HttpClient implements ICanSendHttpRequests
}
}
$parts['path'] = implode('/', $parts2);
$url = Network::unparseURL($parts);
$url = (string)Uri::fromParts((array)$parts);
if (Network::isUrlBlocked($url)) {
$this->logger->info('Domain is blocked.', ['url' => $url]);

View file

@ -21,10 +21,9 @@
namespace Friendica\Network\HTTPClient\Response;
use Friendica\Core\Logger;
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
use Friendica\Network\HTTPException\UnprocessableEntityException;
use Friendica\Util\Network;
use GuzzleHttp\Psr7\Uri;
use Psr\Log\LoggerInterface;
/**
@ -224,7 +223,7 @@ class CurlResult implements ICanHandleHttpResponses
}
}
$this->redirectUrl = Network::unparseURL($redirect_parts);
$this->redirectUrl = (string)Uri::fromParts((array)$redirect_parts);
$this->isRedirectUrl = true;
} else {

View file

@ -1660,7 +1660,7 @@ class Probe
unset($baseParts['query']);
unset($baseParts['fragment']);
return Network::unparseURL((array)$baseParts);
return (string)Uri::fromParts((array)(array)$baseParts);
}
/**

View file

@ -400,7 +400,7 @@ class Network
];
$parts = array_merge($base, parse_url('/' . ltrim($url, '/')));
return self::unparseURL($parts);
return (string)Uri::fromParts((array)$parts);
}
/**
@ -492,38 +492,6 @@ class Network
return Strings::normaliseLink($match);
}
/**
* Glue url parts together
*
* @param array $parsed URL parts
*
* @return string|null The glued URL or null on error
* @deprecated since version 2021.12, use GuzzleHttp\Psr7\Uri::fromParts($parts) instead
*/
public static function unparseURL(array $parsed): string
{
$get = function ($key) use ($parsed) {
return isset($parsed[$key]) ? $parsed[$key] : null;
};
$pass = $get('pass');
$user = $get('user');
$userinfo = $pass !== null ? "$user:$pass" : $user;
$port = $get('port');
$scheme = $get('scheme');
$query = $get('query');
$fragment = $get('fragment');
$authority = ($userinfo !== null ? $userinfo . '@' : '') .
$get('host') .
($port ? ":$port" : '');
return (!empty($scheme) ? $scheme . ':' : '') .
(!empty($authority) ? '//' . $authority : '') .
$get('path') .
(!empty($query) ? '?' . $query : '') .
(!empty($fragment) ? '#' . $fragment : '');
}
/**
* Convert an URI to an IDN compatible URI
*
@ -602,7 +570,7 @@ class Network
$parsed['query'] = http_build_query($params);
return self::unparseURL($parsed);
return (string)Uri::fromParts((array)$parsed);
}
/**