Add new BaseUrl->isLocalUri and BaseUrl->isLocalUrl methods

- Deprecate Util\Network->isLocalLink to reduce dependency on DI class
This commit is contained in:
Hypolite Petovan 2023-07-25 23:13:01 +02:00
parent f1da323b07
commit 148c1c7e1a
2 changed files with 12 additions and 1 deletions

View file

@ -127,4 +127,14 @@ class BaseURL extends Uri implements UriInterface
$redirectTo = $this->__toString() . '/' . ltrim($toUrl, '/'); $redirectTo = $this->__toString() . '/' . ltrim($toUrl, '/');
System::externalRedirect($redirectTo); System::externalRedirect($redirectTo);
} }
public function isLocalUrl(string $url): bool
{
return strpos(Strings::normaliseLink($url), Strings::normaliseLink((string)$this)) === 0;
}
public function isLocalUri(UriInterface $uri): bool
{
return $this->isLocalUrl((string)$uri);
}
} }

View file

@ -640,10 +640,11 @@ class Network
* @param string $url * @param string $url
* *
* @return bool * @return bool
* @deprecated since 2023.09, please use BaseUrl->isLocalUrl or BaseUrl->isLocalUri instead.
*/ */
public static function isLocalLink(string $url): bool public static function isLocalLink(string $url): bool
{ {
return (strpos(Strings::normaliseLink($url), Strings::normaliseLink(DI::baseUrl())) !== false); return DI::baseUrl()->isLocalUrl($url);
} }
/** /**