2017-01-27 12:52:17 +01:00
|
|
|
<?php
|
2019-12-03 19:57:53 +01:00
|
|
|
|
2018-01-16 16:11:51 +01:00
|
|
|
declare(strict_types=1);
|
2019-12-03 19:57:53 +01:00
|
|
|
|
2017-01-27 12:52:17 +01:00
|
|
|
/**
|
2024-05-23 09:26:56 +02:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-01-27 12:52:17 +01:00
|
|
|
*/
|
|
|
|
namespace OC\Federation;
|
|
|
|
|
|
|
|
use OCP\Federation\ICloudId;
|
2025-04-09 10:22:40 +02:00
|
|
|
use OCP\Federation\ICloudIdManager;
|
2017-01-27 12:52:17 +01:00
|
|
|
|
|
|
|
class CloudId implements ICloudId {
|
2025-04-09 10:22:40 +02:00
|
|
|
public function __construct(
|
|
|
|
protected string $id,
|
|
|
|
protected string $user,
|
|
|
|
protected string $remote,
|
|
|
|
protected ?string $displayName = null,
|
|
|
|
) {
|
2017-01-27 12:52:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The full remote cloud id
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-01-16 16:11:51 +01:00
|
|
|
public function getId(): string {
|
2017-01-27 12:52:17 +01:00
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2018-01-16 16:11:51 +01:00
|
|
|
public function getDisplayId(): string {
|
2025-04-09 10:22:40 +02:00
|
|
|
if ($this->displayName === null) {
|
|
|
|
/** @var CloudIdManager $cloudIdManager */
|
|
|
|
$cloudIdManager = \OCP\Server::get(ICloudIdManager::class);
|
|
|
|
$this->displayName = $cloudIdManager->getDisplayNameFromContact($this->getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
$atHost = str_replace(['http://', 'https://'], '', $this->getRemote());
|
|
|
|
|
2020-11-16 17:56:44 +01:00
|
|
|
if ($this->displayName) {
|
2025-04-09 10:22:40 +02:00
|
|
|
return $this->displayName . '@' . $atHost;
|
2020-11-16 17:56:44 +01:00
|
|
|
}
|
2025-04-09 10:22:40 +02:00
|
|
|
return $this->getUser() . '@' . $atHost;
|
2017-01-27 12:52:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The username on the remote server
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-01-16 16:11:51 +01:00
|
|
|
public function getUser(): string {
|
2017-01-27 12:52:17 +01:00
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base address of the remote server
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-01-16 16:11:51 +01:00
|
|
|
public function getRemote(): string {
|
2017-01-27 12:52:17 +01:00
|
|
|
return $this->remote;
|
|
|
|
}
|
2017-02-09 13:32:36 +01:00
|
|
|
}
|