1
0

CloudId.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Federation;
  8. use OCP\Federation\ICloudId;
  9. class CloudId implements ICloudId {
  10. /** @var string */
  11. private $id;
  12. /** @var string */
  13. private $user;
  14. /** @var string */
  15. private $remote;
  16. /** @var string|null */
  17. private $displayName;
  18. /**
  19. * CloudId constructor.
  20. *
  21. * @param string $id
  22. * @param string $user
  23. * @param string $remote
  24. */
  25. public function __construct(string $id, string $user, string $remote, ?string $displayName = null) {
  26. $this->id = $id;
  27. $this->user = $user;
  28. $this->remote = $remote;
  29. $this->displayName = $displayName;
  30. }
  31. /**
  32. * The full remote cloud id
  33. *
  34. * @return string
  35. */
  36. public function getId(): string {
  37. return $this->id;
  38. }
  39. public function getDisplayId(): string {
  40. if ($this->displayName) {
  41. $atPos = strrpos($this->getId(), '@');
  42. $atHost = substr($this->getId(), $atPos);
  43. return $this->displayName . $atHost;
  44. }
  45. return str_replace('https://', '', str_replace('http://', '', $this->getId()));
  46. }
  47. /**
  48. * The username on the remote server
  49. *
  50. * @return string
  51. */
  52. public function getUser(): string {
  53. return $this->user;
  54. }
  55. /**
  56. * The base address of the remote server
  57. *
  58. * @return string
  59. */
  60. public function getRemote(): string {
  61. return $this->remote;
  62. }
  63. }