LazyRoot.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  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, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Files\Node;
  24. use OCP\Files\Cache\ICacheEntry;
  25. use OCP\Files\IRootFolder;
  26. use OCP\Files\Mount\IMountPoint;
  27. use OCP\Files\Node as INode;
  28. /**
  29. * Class LazyRoot
  30. *
  31. * This is a lazy wrapper around the root. So only
  32. * once it is needed this will get initialized.
  33. *
  34. * @package OC\Files\Node
  35. */
  36. class LazyRoot extends LazyFolder implements IRootFolder {
  37. public function __construct(\Closure $folderClosure, array $data = []) {
  38. parent::__construct($this, $folderClosure, $data);
  39. }
  40. protected function getRootFolder(): IRootFolder {
  41. $folder = $this->getRealFolder();
  42. if (!$folder instanceof IRootFolder) {
  43. throw new \Exception('Lazy root folder closure didn\'t return a root folder');
  44. }
  45. return $folder;
  46. }
  47. public function getUserFolder($userId) {
  48. return $this->__call(__FUNCTION__, func_get_args());
  49. }
  50. public function getByIdInPath(int $id, string $path) {
  51. return $this->__call(__FUNCTION__, func_get_args());
  52. }
  53. public function getNodeFromCacheEntryAndMount(ICacheEntry $cacheEntry, IMountPoint $mountPoint): INode {
  54. return $this->getRootFolder()->getNodeFromCacheEntryAndMount($cacheEntry, $mountPoint);
  55. }
  56. }