aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/FederationBundle/Federation/CloudId.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/FederationBundle/Federation/CloudId.php')
-rw-r--r--src/Wallabag/FederationBundle/Federation/CloudId.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/Wallabag/FederationBundle/Federation/CloudId.php b/src/Wallabag/FederationBundle/Federation/CloudId.php
new file mode 100644
index 00000000..038ea5e8
--- /dev/null
+++ b/src/Wallabag/FederationBundle/Federation/CloudId.php
@@ -0,0 +1,78 @@
1<?php
2
3namespace Wallabag\FederationBundle\Federation;
4
5use Wallabag\FederationBundle\Entity\Account;
6
7class CloudId {
8
9 /** @var string */
10 private $id;
11
12 /** @var string */
13 private $user;
14
15 /** @var string */
16 private $remote;
17
18 /**
19 * CloudId constructor.
20 *
21 * @param string $id
22 */
23 public function __construct($id) {
24 $this->id = $id;
25
26 $atPos = strpos($id, '@');
27 $user = substr($id, 0, $atPos);
28 $remote = substr($id, $atPos + 1);
29 if (!empty($user) && !empty($remote)) {
30 $this->user = $user;
31 $this->remote = $remote;
32 }
33 }
34
35 /**
36 * The full remote cloud id
37 *
38 * @return string
39 */
40 public function getId() {
41 return $this->id;
42 }
43
44 public function getDisplayId() {
45 return str_replace('https://', '', str_replace('http://', '', $this->getId()));
46 }
47
48 /**
49 * The username on the remote server
50 *
51 * @return string
52 */
53 public function getUser() {
54 return $this->user;
55 }
56
57 /**
58 * The base address of the remote server
59 *
60 * @return string
61 */
62 public function getRemote() {
63 return $this->remote;
64 }
65
66 /**
67 * @param Account $account
68 * @param string $domain
69 * @return CloudId
70 */
71 public static function getCloudIdFromAccount(Account $account, $domain = '')
72 {
73 if ($account->getServer() !== null) {
74 return new self($account->getUsername() . '@' . $account->getServer());
75 }
76 return new self($account->getUsername() . '@' . $domain);
77 }
78}