mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 09:42:09 -04:00
refactor: Deprecate url generator utils
Add a new IUrlGenerator::linkToRemote and replace usage of the old API with the new one. Signed-off-by: Carl Schwan <carlschwan@kde.org>
This commit is contained in:
parent
8fe81f69f9
commit
ab424e20e2
4 changed files with 31 additions and 8 deletions
|
|
@ -569,7 +569,10 @@ class CloudFederationProviderFiles implements ISignedCloudFederationProvider {
|
|||
$file = null;
|
||||
}
|
||||
$args = Filesystem::is_dir($file) ? ['dir' => $file] : ['dir' => dirname($file), 'scrollto' => $file];
|
||||
$link = Util::linkToAbsolute('files', 'index.php', $args);
|
||||
$urlGenerator = Server::get(IURLGenerator::class);
|
||||
$link = $urlGenerator->getAbsoluteURL(
|
||||
$urlGenerator->linkTo('files', 'index.php', $args)
|
||||
);
|
||||
|
||||
return [$file, $link];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use OCP\IRequest;
|
|||
use OCP\IURLGenerator;
|
||||
use OCP\IUserSession;
|
||||
use OCP\Server;
|
||||
use Override;
|
||||
use RuntimeException;
|
||||
|
||||
class URLGenerator implements IURLGenerator {
|
||||
|
|
@ -326,4 +327,12 @@ class URLGenerator implements IURLGenerator {
|
|||
public function getWebroot(): string {
|
||||
return \OC::$WEBROOT;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function linkToRemote(string $service): string {
|
||||
$remoteBase = $this->linkTo('', 'remote.php') . '/' . $service;
|
||||
return $this->getAbsoluteURL(
|
||||
$remoteBase . (($service[strlen($service) - 1] !== '/') ? '/' : '')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,14 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace OCP;
|
||||
|
||||
use OCP\AppFramework\Attribute\Consumable;
|
||||
|
||||
/**
|
||||
* Class to generate URLs
|
||||
*
|
||||
* @since 6.0.0
|
||||
*/
|
||||
#[Consumable(since: '6.0.0')]
|
||||
interface IURLGenerator {
|
||||
/**
|
||||
* Regex for matching http(s) urls
|
||||
|
|
@ -115,4 +119,11 @@ interface IURLGenerator {
|
|||
* @since 23.0.0
|
||||
*/
|
||||
public function getWebroot(): string;
|
||||
|
||||
/**
|
||||
* Return the url to the remote DAV handler.
|
||||
*
|
||||
* @since 34.0.0
|
||||
*/
|
||||
public function linkToRemote(string $service): string;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -236,9 +236,10 @@ class Util {
|
|||
* The value of $args will be urlencoded
|
||||
* @return string the url
|
||||
* @since 4.0.0 - parameter $args was added in 4.5.0
|
||||
* @deprecated 34.0.0 Use IUrlGenerator::getAbsoluteUrl and IUrlGenerator::linkTo
|
||||
*/
|
||||
public static function linkToAbsolute($app, $file, $args = []) {
|
||||
$urlGenerator = \OCP\Server::get(IURLGenerator::class);
|
||||
$urlGenerator = Server::get(IURLGenerator::class);
|
||||
return $urlGenerator->getAbsoluteURL(
|
||||
$urlGenerator->linkTo($app, $file, $args)
|
||||
);
|
||||
|
|
@ -246,16 +247,15 @@ class Util {
|
|||
|
||||
/**
|
||||
* Creates an absolute url for remote use.
|
||||
*
|
||||
* @param string $service id
|
||||
* @return string the url
|
||||
* @since 4.0.0
|
||||
* @deprecated 34.0.0 Use IURlGenerator::linkToRemote
|
||||
*/
|
||||
public static function linkToRemote($service) {
|
||||
$urlGenerator = \OCP\Server::get(IURLGenerator::class);
|
||||
$remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service;
|
||||
return $urlGenerator->getAbsoluteURL(
|
||||
$remoteBase . (($service[strlen($service) - 1] !== '/') ? '/' : '')
|
||||
);
|
||||
public static function linkToRemote(string $service): string {
|
||||
$urlGenerator = Server::get(IURLGenerator::class);
|
||||
return $urlGenerator->linkToRemote($service);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue