aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/Config/LazyPathCachedMountInfo.php
blob: d2396109b1a69dc479b80d3be840a48acabf2a7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

declare(strict_types=1);
/**
 * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OC\Files\Config;

use OCP\IUser;

class LazyPathCachedMountInfo extends CachedMountInfo {
	// we don't allow \ in paths so it makes a great placeholder
	private const PATH_PLACEHOLDER = '\\PLACEHOLDER\\';

	/** @var callable(CachedMountInfo): string */
	protected $rootInternalPathCallback;

	/**
	 * @param IUser $user
	 * @param int $storageId
	 * @param int $rootId
	 * @param string $mountPoint
	 * @param string $mountProvider
	 * @param int|null $mountId
	 * @param callable(CachedMountInfo): string $rootInternalPathCallback
	 * @throws \Exception
	 */
	public function __construct(
		IUser $user,
		int $storageId,
		int $rootId,
		string $mountPoint,
		string $mountProvider,
		?int $mountId,
		callable $rootInternalPathCallback,
	) {
		parent::__construct($user, $storageId, $rootId, $mountPoint, $mountProvider, $mountId, self::PATH_PLACEHOLDER);
		$this->rootInternalPathCallback = $rootInternalPathCallback;
	}

	public function getRootInternalPath(): string {
		if ($this->rootInternalPath === self::PATH_PLACEHOLDER) {
			$this->rootInternalPath = ($this->rootInternalPathCallback)($this);
		}
		return $this->rootInternalPath;
	}
}