From bf6c0346d8d35a719dd1bff1cb4d573d422f99ff Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 31 May 2017 09:31:18 +0200 Subject: WIP Signed-off-by: Thomas Citharel --- .../FederationBundle/Federation/CloudId.php | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/Wallabag/FederationBundle/Federation/CloudId.php (limited to 'src/Wallabag/FederationBundle/Federation/CloudId.php') 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 @@ +id = $id; + + $atPos = strpos($id, '@'); + $user = substr($id, 0, $atPos); + $remote = substr($id, $atPos + 1); + if (!empty($user) && !empty($remote)) { + $this->user = $user; + $this->remote = $remote; + } + } + + /** + * The full remote cloud id + * + * @return string + */ + public function getId() { + return $this->id; + } + + public function getDisplayId() { + return str_replace('https://', '', str_replace('http://', '', $this->getId())); + } + + /** + * The username on the remote server + * + * @return string + */ + public function getUser() { + return $this->user; + } + + /** + * The base address of the remote server + * + * @return string + */ + public function getRemote() { + return $this->remote; + } + + /** + * @param Account $account + * @param string $domain + * @return CloudId + */ + public static function getCloudIdFromAccount(Account $account, $domain = '') + { + if ($account->getServer() !== null) { + return new self($account->getUsername() . '@' . $account->getServer()); + } + return new self($account->getUsername() . '@' . $domain); + } +} -- cgit v1.2.3