Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Tidy up typing in OC\Files\View
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Apr 3, 2023
commit 966a3e696335d9dad2cc8dfa2ec44d44298626ff
3 changes: 1 addition & 2 deletions apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function rename($path1, $path2) {
return $this->canRename;
}

public function getRelativePath($path) {
public function getRelativePath($path): ?string {
return $path;
}
}
Expand All @@ -73,7 +73,6 @@ public function getRelativePath($path) {
* @group DB
*/
class DirectoryTest extends \Test\TestCase {

use UserTrait;

/** @var \OC\Files\View | \PHPUnit\Framework\MockObject\MockObject */
Expand Down
65 changes: 23 additions & 42 deletions lib/private/Files/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,24 @@
use OC\User\NoUserException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Events\Node\FilesystemTornDownEvent;
use OCP\Files\Mount\IMountManager;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;

class Filesystem {
/**
* @var Mount\Manager $mounts
*/
private static $mounts;

public static $loaded = false;
/**
* @var \OC\Files\View $defaultInstance
*/
private static $defaultInstance;
private static ?Mount\Manager $mounts = null;

private static $usersSetup = [];
public static bool $loaded = false;

private static $normalizedPathCache = null;
private static ?View $defaultInstance = null;

private static $listeningForProviders = false;
private static ?CappedMemoryCache $normalizedPathCache = null;

/** @var string[]|null */
private static $blacklist = null;
private static ?array $blacklist = null;

/**
* classname which used for hooks handling
Expand Down Expand Up @@ -186,22 +178,18 @@ class Filesystem {
public const signal_param_mount_type = 'mounttype';
public const signal_param_users = 'users';

/**
* @var \OC\Files\Storage\StorageFactory $loader
*/
private static $loader;
private static ?\OC\Files\Storage\StorageFactory $loader = null;

/** @var bool */
private static $logWarningWhenAddingStorageWrapper = true;
private static bool $logWarningWhenAddingStorageWrapper = true;

/**
* @param bool $shouldLog
* @return bool previous value
* @internal
*/
public static function logWarningWhenAddingStorageWrapper($shouldLog) {
public static function logWarningWhenAddingStorageWrapper(bool $shouldLog): bool {
$previousValue = self::$logWarningWhenAddingStorageWrapper;
self::$logWarningWhenAddingStorageWrapper = (bool) $shouldLog;
self::$logWarningWhenAddingStorageWrapper = $shouldLog;
return $previousValue;
}

Expand Down Expand Up @@ -232,18 +220,17 @@ public static function addStorageWrapper($wrapperName, $wrapper, $priority = 50)
*/
public static function getLoader() {
if (!self::$loader) {
self::$loader = \OC::$server->query(IStorageFactory::class);
self::$loader = \OC::$server->get(IStorageFactory::class);
}
return self::$loader;
}

/**
* Returns the mount manager
*
* @return \OC\Files\Mount\Manager
*/
public static function getMountManager($user = '') {
public static function getMountManager(): Mount\Manager {
self::initMountManager();
assert(self::$mounts !== null);
return self::$mounts;
}

Expand Down Expand Up @@ -313,14 +300,14 @@ public static function getMountByNumericId($id) {
* resolve a path to a storage and internal path
*
* @param string $path
* @return array an array consisting of the storage and the internal path
* @return array{?\OCP\Files\Storage\IStorage, string} an array consisting of the storage and the internal path
*/
public static function resolvePath($path) {
public static function resolvePath($path): array {
$mount = self::getMountManager()->find($path);
return [$mount->getStorage(), rtrim($mount->getInternalPath($path), '/')];
}

public static function init($user, $root) {
public static function init(string|IUser|null $user, string $root): bool {
if (self::$defaultInstance) {
return false;
}
Expand All @@ -332,7 +319,7 @@ public static function init($user, $root) {
return true;
}

public static function initInternal($root) {
public static function initInternal(string $root): bool {
if (self::$defaultInstance) {
return false;
}
Expand All @@ -342,32 +329,28 @@ public static function initInternal($root) {
$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
$eventDispatcher->addListener(FilesystemTornDownEvent::class, function () {
self::$defaultInstance = null;
self::$usersSetup = [];
self::$loaded = false;
});

if (!self::$mounts) {
self::$mounts = \OC::$server->getMountManager();
}
self::initMountManager();

self::$loaded = true;

return true;
}

public static function initMountManager() {
public static function initMountManager(): void {
if (!self::$mounts) {
self::$mounts = \OC::$server->getMountManager();
self::$mounts = \OC::$server->get(IMountManager::class);
}
}

/**
* Initialize system and personal mount points for a user
*
* @param string|IUser|null $user
* @throws \OC\User\NoUserException if the user is not available
*/
public static function initMountPoints($user = '') {
public static function initMountPoints(string|IUser|null $user = ''): void {
/** @var IUserManager $userManager */
$userManager = \OC::$server->get(IUserManager::class);

Expand All @@ -382,11 +365,9 @@ public static function initMountPoints($user = '') {
}

/**
* get the default filesystem view
*
* @return View
* Get the default filesystem view
*/
public static function getView() {
public static function getView(): ?View {
if (!self::$defaultInstance) {
/** @var IUserSession $session */
$session = \OC::$server->get(IUserSession::class);
Expand Down
Loading