1
0

CloudId.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2017, Robin Appelman <robin@icewind.nl>
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OC\Federation;
  27. use OCP\Federation\ICloudId;
  28. class CloudId implements ICloudId {
  29. /** @var string */
  30. private $id;
  31. /** @var string */
  32. private $user;
  33. /** @var string */
  34. private $remote;
  35. /** @var string|null */
  36. private $displayName;
  37. /**
  38. * CloudId constructor.
  39. *
  40. * @param string $id
  41. * @param string $user
  42. * @param string $remote
  43. */
  44. public function __construct(string $id, string $user, string $remote, ?string $displayName = null) {
  45. $this->id = $id;
  46. $this->user = $user;
  47. $this->remote = $remote;
  48. $this->displayName = $displayName;
  49. }
  50. /**
  51. * The full remote cloud id
  52. *
  53. * @return string
  54. */
  55. public function getId(): string {
  56. return $this->id;
  57. }
  58. public function getDisplayId(): string {
  59. if ($this->displayName) {
  60. $atPos = strrpos($this->getId(), '@');
  61. $atHost = substr($this->getId(), $atPos);
  62. return $this->displayName . $atHost;
  63. }
  64. return str_replace('https://', '', str_replace('http://', '', $this->getId()));
  65. }
  66. /**
  67. * The username on the remote server
  68. *
  69. * @return string
  70. */
  71. public function getUser(): string {
  72. return $this->user;
  73. }
  74. /**
  75. * The base address of the remote server
  76. *
  77. * @return string
  78. */
  79. public function getRemote(): string {
  80. return $this->remote;
  81. }
  82. }