LazyRoot.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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;
  28. use OCP\Files\Node as INode;
  29. /**
  30. * Class LazyRoot
  31. *
  32. * This is a lazy wrapper around the root. So only
  33. * once it is needed this will get initialized.
  34. *
  35. * @package OC\Files\Node
  36. */
  37. class LazyRoot extends LazyFolder implements IRootFolder {
  38. public function __construct(\Closure $folderClosure, array $data = []) {
  39. parent::__construct($this, $folderClosure, $data);
  40. }
  41. protected function getRootFolder(): IRootFolder {
  42. $folder = $this->getRealFolder();
  43. if (!$folder instanceof IRootFolder) {
  44. throw new \Exception('Lazy root folder closure didn\'t return a root folder');
  45. }
  46. return $folder;
  47. }
  48. public function getUserFolder($userId) {
  49. return $this->__call(__FUNCTION__, func_get_args());
  50. }
  51. public function getByIdInPath(int $id, string $path) {
  52. return $this->__call(__FUNCTION__, func_get_args());
  53. }
  54. public function getFirstNodeByIdInPath(int $id, string $path): ?Node {
  55. return $this->__call(__FUNCTION__, func_get_args());
  56. }
  57. public function getNodeFromCacheEntryAndMount(ICacheEntry $cacheEntry, IMountPoint $mountPoint): INode {
  58. return $this->getRootFolder()->getNodeFromCacheEntryAndMount($cacheEntry, $mountPoint);
  59. }
  60. }