|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl> |
| 6 | + * |
| 7 | + * @license GNU AGPL version 3 or any later version |
| 8 | + * |
| 9 | + * This program is free software: you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU Affero General Public License as |
| 11 | + * published by the Free Software Foundation, either version 3 of the |
| 12 | + * License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU Affero General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU Affero General Public License |
| 20 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | + * |
| 22 | + */ |
| 23 | + |
| 24 | +namespace OC\User; |
| 25 | + |
| 26 | +use OCP\IUser; |
| 27 | +use OCP\IUserManager; |
| 28 | + |
| 29 | +class LazyUser implements IUser { |
| 30 | + private ?IUser $user = null; |
| 31 | + private DisplayNameCache $displayNameCache; |
| 32 | + private string $uid; |
| 33 | + private IUserManager $userManager; |
| 34 | + |
| 35 | + public function __construct(string $uid, DisplayNameCache $displayNameCache, IUserManager $userManager) { |
| 36 | + $this->displayNameCache = $displayNameCache; |
| 37 | + $this->uid = $uid; |
| 38 | + $this->userManager = $userManager; |
| 39 | + } |
| 40 | + |
| 41 | + private function getUser(): IUser { |
| 42 | + if ($this->user === null) { |
| 43 | + $this->user = $this->userManager->get($this->uid); |
| 44 | + } |
| 45 | + return $this->user; |
| 46 | + } |
| 47 | + |
| 48 | + public function getUID() { |
| 49 | + return $this->uid; |
| 50 | + } |
| 51 | + |
| 52 | + public function getDisplayName() { |
| 53 | + return $this->displayNameCache->getDisplayName($this->uid); |
| 54 | + } |
| 55 | + |
| 56 | + public function setDisplayName($displayName) { |
| 57 | + return $this->getUser()->setDisplayName($displayName); |
| 58 | + } |
| 59 | + |
| 60 | + public function getLastLogin() { |
| 61 | + return $this->getUser()->getLastLogin(); |
| 62 | + } |
| 63 | + |
| 64 | + public function updateLastLoginTimestamp() { |
| 65 | + return $this->getUser()->updateLastLoginTimestamp(); |
| 66 | + } |
| 67 | + |
| 68 | + public function delete() { |
| 69 | + return $this->getUser()->delete(); |
| 70 | + } |
| 71 | + |
| 72 | + public function setPassword($password, $recoveryPassword = null) { |
| 73 | + return $this->getUser()->setPassword($password, $recoveryPassword); |
| 74 | + } |
| 75 | + |
| 76 | + public function getHome() { |
| 77 | + return $this->getUser()->getHome(); |
| 78 | + } |
| 79 | + |
| 80 | + public function getBackendClassName() { |
| 81 | + return $this->getUser()->getBackendClassName(); |
| 82 | + } |
| 83 | + |
| 84 | + public function getBackend() { |
| 85 | + return $this->getUser()->getBackend(); |
| 86 | + } |
| 87 | + |
| 88 | + public function canChangeAvatar() { |
| 89 | + return $this->getUser()->canChangeAvatar(); |
| 90 | + } |
| 91 | + |
| 92 | + public function canChangePassword() { |
| 93 | + return $this->getUser()->canChangePassword(); |
| 94 | + } |
| 95 | + |
| 96 | + public function canChangeDisplayName() { |
| 97 | + return $this->getUser()->canChangeDisplayName(); |
| 98 | + } |
| 99 | + |
| 100 | + public function isEnabled() { |
| 101 | + return $this->getUser()->isEnabled(); |
| 102 | + } |
| 103 | + |
| 104 | + public function setEnabled(bool $enabled = true) { |
| 105 | + return $this->getUser()->setEnabled($enabled); |
| 106 | + } |
| 107 | + |
| 108 | + public function getEMailAddress() { |
| 109 | + return $this->getUser()->getEMailAddress(); |
| 110 | + } |
| 111 | + |
| 112 | + public function getSystemEMailAddress(): ?string { |
| 113 | + return $this->getUser()->getSystemEMailAddress(); |
| 114 | + } |
| 115 | + |
| 116 | + public function getPrimaryEMailAddress(): ?string { |
| 117 | + return $this->getUser()->getPrimaryEMailAddress(); |
| 118 | + } |
| 119 | + |
| 120 | + public function getAvatarImage($size) { |
| 121 | + return $this->getUser()->getAvatarImage($size); |
| 122 | + } |
| 123 | + |
| 124 | + public function getCloudId() { |
| 125 | + return $this->getUser()->getCloudId(); |
| 126 | + } |
| 127 | + |
| 128 | + public function setEMailAddress($mailAddress) { |
| 129 | + $this->getUser()->setEMailAddress($mailAddress); |
| 130 | + } |
| 131 | + |
| 132 | + public function setSystemEMailAddress(string $mailAddress): void { |
| 133 | + $this->getUser()->setSystemEMailAddress($mailAddress); |
| 134 | + } |
| 135 | + |
| 136 | + public function setPrimaryEMailAddress(string $mailAddress): void { |
| 137 | + $this->getUser()->setPrimaryEMailAddress($mailAddress); |
| 138 | + } |
| 139 | + |
| 140 | + public function getQuota() { |
| 141 | + return $this->getUser()->getQuota(); |
| 142 | + } |
| 143 | + |
| 144 | + public function setQuota($quota) { |
| 145 | + $this->getUser()->setQuota($quota); |
| 146 | + } |
| 147 | + |
| 148 | + |
| 149 | +} |
0 commit comments