1
0

LazyPathCachedMountInfo.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Files\Config;
  8. use OCP\IUser;
  9. class LazyPathCachedMountInfo extends CachedMountInfo {
  10. // we don't allow \ in paths so it makes a great placeholder
  11. private const PATH_PLACEHOLDER = '\\PLACEHOLDER\\';
  12. /** @var callable(CachedMountInfo): string */
  13. protected $rootInternalPathCallback;
  14. /**
  15. * @param IUser $user
  16. * @param int $storageId
  17. * @param int $rootId
  18. * @param string $mountPoint
  19. * @param string $mountProvider
  20. * @param int|null $mountId
  21. * @param callable(CachedMountInfo): string $rootInternalPathCallback
  22. * @throws \Exception
  23. */
  24. public function __construct(
  25. IUser $user,
  26. int $storageId,
  27. int $rootId,
  28. string $mountPoint,
  29. string $mountProvider,
  30. ?int $mountId,
  31. callable $rootInternalPathCallback,
  32. ) {
  33. parent::__construct($user, $storageId, $rootId, $mountPoint, $mountProvider, $mountId, self::PATH_PLACEHOLDER);
  34. $this->rootInternalPathCallback = $rootInternalPathCallback;
  35. }
  36. public function getRootInternalPath(): string {
  37. if ($this->rootInternalPath === self::PATH_PLACEHOLDER) {
  38. $this->rootInternalPath = ($this->rootInternalPathCallback)($this);
  39. }
  40. return $this->rootInternalPath;
  41. }
  42. }