1
0

LazyUser.php 3.7 KB

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