LazyRoot.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Files\Node;
  8. use OCP\Files\Cache\ICacheEntry;
  9. use OCP\Files\IRootFolder;
  10. use OCP\Files\Mount\IMountPoint;
  11. use OCP\Files\Node;
  12. use OCP\Files\Node as INode;
  13. /**
  14. * Class LazyRoot
  15. *
  16. * This is a lazy wrapper around the root. So only
  17. * once it is needed this will get initialized.
  18. *
  19. * @package OC\Files\Node
  20. */
  21. class LazyRoot extends LazyFolder implements IRootFolder {
  22. public function __construct(\Closure $folderClosure, array $data = []) {
  23. parent::__construct($this, $folderClosure, $data);
  24. }
  25. protected function getRootFolder(): IRootFolder {
  26. $folder = $this->getRealFolder();
  27. if (!$folder instanceof IRootFolder) {
  28. throw new \Exception('Lazy root folder closure didn\'t return a root folder');
  29. }
  30. return $folder;
  31. }
  32. public function getUserFolder($userId) {
  33. return $this->__call(__FUNCTION__, func_get_args());
  34. }
  35. public function getByIdInPath(int $id, string $path) {
  36. return $this->__call(__FUNCTION__, func_get_args());
  37. }
  38. public function getFirstNodeByIdInPath(int $id, string $path): ?Node {
  39. return $this->__call(__FUNCTION__, func_get_args());
  40. }
  41. public function getNodeFromCacheEntryAndMount(ICacheEntry $cacheEntry, IMountPoint $mountPoint): INode {
  42. return $this->getRootFolder()->getNodeFromCacheEntryAndMount($cacheEntry, $mountPoint);
  43. }
  44. public function getAppDataDirectoryName(): string {
  45. return $this->__call(__FUNCTION__, func_get_args());
  46. }
  47. }