diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php
index 94cbbdbbabd40..d8b50bd4bea00 100644
--- a/apps/dav/lib/Connector/Sabre/ServerFactory.php
+++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php
@@ -137,7 +137,12 @@ public function createServer(
$server->on('beforeMethod:*', function () use ($server,
$tree, $viewCallBack, $isPublicShare, $rootCollection, $debugEnabled): void {
// ensure the skeleton is copied
- $userFolder = \OC::$server->getUserFolder();
+ $userFolder = null;
+ $rootFolder = \OCP\Server::get(IRootFolder::class);
+ $user = $this->userSession->getUser();
+ if ($user !== null) {
+ $userFolder = $rootFolder->getUserFolder($user->getUID());
+ }
/** @var View $view */
$view = $viewCallBack($server);
@@ -188,7 +193,7 @@ public function createServer(
$tree,
$this->userSession,
\OCP\Server::get(\OCP\Share\IManager::class),
- \OCP\Server::get(IRootFolder::class),
+ $rootFolder,
));
$server->addPlugin(new CommentPropertiesPlugin(\OCP\Server::get(ICommentsManager::class), $this->userSession));
$server->addPlugin(new FilesReportPlugin(
@@ -209,7 +214,7 @@ public function createServer(
$server,
$tree,
$this->databaseConnection,
- $this->userSession->getUser(),
+ $user,
\OCP\Server::get(PropertyMapper::class),
\OCP\Server::get(DefaultCalendarValidator::class),
)
diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php
index 9ccd975dfa3bd..4e286f408b2bc 100644
--- a/apps/dav/lib/Server.php
+++ b/apps/dav/lib/Server.php
@@ -288,15 +288,17 @@ public function __construct(
// wait with registering these until auth is handled and the filesystem is setup
$this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend, $logger): void {
- // Allow view-only plugin for webdav requests
- $this->server->addPlugin(new ViewOnlyPlugin(
- \OC::$server->getUserFolder(),
- ));
-
// custom properties plugin must be the last one
$userSession = \OCP\Server::get(IUserSession::class);
$user = $userSession->getUser();
- if ($user !== null) {
+ $rootFolder = \OCP\Server::get(IRootFolder::class);
+ if ($user === null) {
+ // Allow view-only plugin for webdav requests
+ $this->server->addPlugin(new ViewOnlyPlugin(null));
+ } else {
+ $userFolder = $rootFolder->getUserFolder($user->getUID());
+ // Allow view-only plugin for webdav requests
+ $this->server->addPlugin(new ViewOnlyPlugin($userFolder));
$view = Filesystem::getView();
$config = \OCP\Server::get(IConfig::class);
$this->server->addPlugin(
@@ -337,13 +339,12 @@ public function __construct(
);
// TODO: switch to LazyUserFolder
- $userFolder = \OC::$server->getUserFolder();
$shareManager = \OCP\Server::get(\OCP\Share\IManager::class);
$this->server->addPlugin(new SharesPlugin(
$this->server->tree,
$userSession,
$shareManager,
- \OCP\Server::get(IRootFolder::class),
+ $rootFolder,
));
$this->server->addPlugin(new CommentPropertiesPlugin(
\OCP\Server::get(ICommentsManager::class),
@@ -381,7 +382,7 @@ public function __construct(
$this->server,
$this->server->tree,
$user,
- \OCP\Server::get(IRootFolder::class),
+ $rootFolder,
$shareManager,
$view,
\OCP\Server::get(IFilesMetadataManager::class)
diff --git a/apps/dav/tests/unit/AppInfo/ApplicationTest.php b/apps/dav/tests/unit/AppInfo/ApplicationTest.php
index 14bf89fb93bdd..07437b27b4cf4 100644
--- a/apps/dav/tests/unit/AppInfo/ApplicationTest.php
+++ b/apps/dav/tests/unit/AppInfo/ApplicationTest.php
@@ -27,9 +27,9 @@ public function test(): void {
$c = $app->getContainer();
// assert service instances in the container are properly setup
- $s = $c->query(ContactsManager::class);
+ $s = $c->get(ContactsManager::class);
$this->assertInstanceOf(ContactsManager::class, $s);
- $s = $c->query(CardDavBackend::class);
+ $s = $c->get(CardDavBackend::class);
$this->assertInstanceOf(CardDavBackend::class, $s);
}
}
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php
index 2fd5617254904..53c3f7d98e56d 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php
@@ -9,6 +9,7 @@
namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
+use OCP\Files\IRootFolder;
use OCP\IUserSession;
use OCP\Server;
use Sabre\DAV\Auth\Backend\BackendInterface;
@@ -64,7 +65,7 @@ public function check(RequestInterface $request, ResponseInterface $response) {
$user = $userSession->getUser()->getUID();
\OC_Util::setupFS($user);
//trigger creation of user home and /files folder
- \OC::$server->getUserFolder($user);
+ Server::get(IRootFolder::class)->getUserFolder($user);
return [true, "principals/$user"];
}
return [false, 'login failed'];
diff --git a/apps/files_sharing/lib/Updater.php b/apps/files_sharing/lib/Updater.php
index e2c0eef89706f..bccb452f612ef 100644
--- a/apps/files_sharing/lib/Updater.php
+++ b/apps/files_sharing/lib/Updater.php
@@ -13,8 +13,10 @@
use OC\Files\Mount\MountPoint;
use OCP\Constants;
use OCP\Files\Folder;
+use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\NotFoundException;
+use OCP\IUserSession;
use OCP\Server;
use OCP\Share\IShare;
@@ -39,7 +41,11 @@ public static function renameHook($params) {
* @param string $path
*/
private static function moveShareInOrOutOfShare($path): void {
- $userFolder = \OC::$server->getUserFolder();
+ $userInSession = Server::get(IUserSession::class)->getUser();
+ if (!$userInSession) {
+ return;
+ }
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder($userInSession->getUID());
// If the user folder can't be constructed (e.g. link share) just return.
if ($userFolder === null) {
diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php
index 04c56e7b6552a..add63e8141c1e 100644
--- a/apps/files_sharing/tests/ApiTest.php
+++ b/apps/files_sharing/tests/ApiTest.php
@@ -86,7 +86,7 @@ protected function setUp(): void {
$mount = $this->view->getMount($this->filename);
$mount->getStorage()->getScanner()->scan('', Scanner::SCAN_RECURSIVE);
- $this->userFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $this->userFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$this->appConfig = $this->createMock(IAppConfig::class);
}
@@ -870,7 +870,7 @@ public function testGetShareFromFileReReShares(): void {
$share1->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share1);
- $user2Folder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2);
+ $user2Folder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER2);
$node2 = $user2Folder->get($this->subfolder . $this->filename);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
@@ -882,7 +882,7 @@ public function testGetShareFromFileReReShares(): void {
$share2->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share2);
- $user3Folder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER3);
+ $user3Folder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER3);
$node3 = $user3Folder->get($this->filename);
$share3 = $this->shareManager->newShare();
$share3->setNode($node3)
@@ -1133,7 +1133,7 @@ public function testDeleteReshare(): void {
$share1->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share1);
- $user2folder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2);
+ $user2folder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER2);
$node2 = $user2folder->get($this->folder . '/' . $this->filename);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php
index 47ca960c7a119..863ee4e21e845 100644
--- a/apps/files_sharing/tests/CacheTest.php
+++ b/apps/files_sharing/tests/CacheTest.php
@@ -68,7 +68,7 @@ protected function setUp(): void {
$this->ownerStorage->getScanner()->scan('');
// share "shareddir" with user2
- $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $rootFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('container/shareddir');
$share = $this->shareManager->newShare();
@@ -286,7 +286,7 @@ public function testGetFolderContentsInSubdir(): void {
public function testShareRenameOriginalFileInRecentResults(): void {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $rootFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('simplefile.txt');
$share = $this->shareManager->newShare();
$share->setNode($node)
@@ -302,7 +302,7 @@ public function testShareRenameOriginalFileInRecentResults(): void {
$node->move(self::TEST_FILES_SHARING_API_USER1 . '/files/simplefile2.txt');
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
- $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER3);
+ $rootFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER3);
$recents = $rootFolder->getRecent(10);
self::assertEquals([
'welcome.txt',
@@ -313,7 +313,7 @@ public function testShareRenameOriginalFileInRecentResults(): void {
public function testGetFolderContentsWhenSubSubdirShared(): void {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $rootFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('container/shareddir/subdir');
$share = $this->shareManager->newShare();
$share->setNode($node)
@@ -399,7 +399,7 @@ public function testGetPathByIdDirectShare(): void {
Filesystem::file_put_contents('test.txt', 'foo');
$info = Filesystem::getFileInfo('test.txt');
- $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $rootFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('test.txt');
$share = $this->shareManager->newShare();
$share->setNode($node)
@@ -430,7 +430,7 @@ public function testGetPathByIdShareSubFolder(): void {
$folderInfo = Filesystem::getFileInfo('foo');
$fileInfo = Filesystem::getFileInfo('foo/bar/test.txt');
- $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $rootFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('foo');
$share = $this->shareManager->newShare();
$share->setNode($node)
@@ -458,7 +458,7 @@ public function testNumericStorageId(): void {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
Filesystem::mkdir('foo');
- $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $rootFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('foo');
$share = $this->shareManager->newShare();
$share->setNode($node)
@@ -495,7 +495,7 @@ public function testShareJailedStorage(): void {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $rootFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('foo/sub');
$share = $this->shareManager->newShare();
$share->setNode($node)
@@ -534,7 +534,7 @@ public function testSearchShareJailedStorage(): void {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $rootFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('foo/sub');
$share = $this->shareManager->newShare();
$share->setNode($node)
@@ -571,7 +571,7 @@ public function testSingleFileShareKeepsUnmaskedPermissionsAsScanPermissions():
public function testFolderShareKeepsUnmaskedPermissionsAsScanPermissions(): void {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
- $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
+ $rootFolder = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('container');
$share = $this->shareManager->newShare();
$share->setNode($node)
diff --git a/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php b/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
index 9087dc075a08e..628b5ad4deb1d 100644
--- a/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
+++ b/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php
@@ -14,6 +14,7 @@
use OCA\Files_Trashbin\Storage;
use OCP\App\IAppManager;
use OCP\Constants;
+use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IUserManager;
use OCP\Server;
@@ -125,7 +126,7 @@ private function getShares() {
public function testClearShares(): void {
$this->loginAsUser($this->user1);
- $user1Folder = \OC::$server->getUserFolder($this->user1);
+ $user1Folder = Server::get(IRootFolder::class)->getUserFolder($this->user1);
$testFolder = $user1Folder->newFolder('test');
$testSubFolder = $testFolder->newFolder('sub');
diff --git a/apps/files_sharing/tests/EtagPropagationTest.php b/apps/files_sharing/tests/EtagPropagationTest.php
index 551e744f7493e..954518d6738be 100644
--- a/apps/files_sharing/tests/EtagPropagationTest.php
+++ b/apps/files_sharing/tests/EtagPropagationTest.php
@@ -256,7 +256,7 @@ public function testOwnerUnshares(): void {
$folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
- $node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder');
+ $node = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder');
$shareManager = Server::get(\OCP\Share\IManager::class);
$shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node, true);
@@ -279,7 +279,7 @@ public function testOwnerUnsharesFlatReshares(): void {
$folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder/inside');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
- $node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder/inside');
+ $node = Server::get(IRootFolder::class)->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder/inside');
$shareManager = Server::get(\OCP\Share\IManager::class);
$shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node, true);
diff --git a/apps/files_trashbin/lib/Command/Expire.php b/apps/files_trashbin/lib/Command/Expire.php
index fad9bc574387c..0fac6488f7196 100644
--- a/apps/files_trashbin/lib/Command/Expire.php
+++ b/apps/files_trashbin/lib/Command/Expire.php
@@ -8,7 +8,6 @@
namespace OCA\Files_Trashbin\Command;
-use OC\Command\FileAccess;
use OC\Files\SetupManager;
use OCA\Files_Trashbin\Trashbin;
use OCP\Command\ICommand;
@@ -20,8 +19,6 @@
use Psr\Log\LoggerInterface;
class Expire implements ICommand {
- use FileAccess;
-
public function __construct(
private readonly string $userId,
) {
diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php
index 9779f36c0e830..a7ffd8364c0cf 100644
--- a/apps/files_trashbin/lib/Trashbin.php
+++ b/apps/files_trashbin/lib/Trashbin.php
@@ -668,7 +668,7 @@ private static function restoreVersions(View $view, $file, $filename, $uniqueFil
*/
public static function deleteAll() {
$user = OC_User::getUser();
- $userRoot = \OC::$server->getUserFolder($user)->getParent();
+ $userRoot = Server::get(IRootFolder::class)->getUserFolder($user)->getParent();
$view = new View('/' . $user);
$fileInfos = $view->getDirectoryContent('files_trashbin/files');
@@ -743,7 +743,7 @@ protected static function emitTrashbinPostDelete($path) {
* @return int|float size of deleted files
*/
public static function delete($filename, $user, $timestamp = null) {
- $userRoot = \OC::$server->getUserFolder($user)->getParent();
+ $userRoot = Server::get(IRootFolder::class)->getUserFolder($user)->getParent();
$view = new View('/' . $user);
$size = 0;
diff --git a/apps/files_trashbin/tests/TrashbinTest.php b/apps/files_trashbin/tests/TrashbinTest.php
index d71610eb05dc5..7abb28f2e91be 100644
--- a/apps/files_trashbin/tests/TrashbinTest.php
+++ b/apps/files_trashbin/tests/TrashbinTest.php
@@ -78,7 +78,7 @@ public static function setUpBeforeClass(): void {
// register trashbin hooks
$trashbinApp = new TrashbinApplication();
- $trashbinApp->boot(new BootContext(new DIContainer('', [], \OC::$server)));
+ $trashbinApp->boot(new BootContext(\OC::$server, new DIContainer('', [], \OC::$server)));
// create test user
self::loginHelper(self::TEST_TRASHBIN_USER2, true);
@@ -218,7 +218,7 @@ public function testExpireOldFilesShared(): void {
Filesystem::file_put_contents($folder . 'user1-4.txt', 'file4');
//share user1-4.txt with user2
- $node = \OC::$server->getUserFolder(self::TEST_TRASHBIN_USER1)->get($folder);
+ $node = Server::get(IRootFolder::class)->getUserFolder(self::TEST_TRASHBIN_USER1)->get($folder);
$share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setShareType(IShare::TYPE_USER)
->setNode($node)
diff --git a/apps/files_versions/lib/Command/Expire.php b/apps/files_versions/lib/Command/Expire.php
index 995f9a59f0b03..c4c04ff03019d 100644
--- a/apps/files_versions/lib/Command/Expire.php
+++ b/apps/files_versions/lib/Command/Expire.php
@@ -8,7 +8,6 @@
namespace OCA\Files_Versions\Command;
-use OC\Command\FileAccess;
use OCA\Files_Versions\Storage;
use OCP\Command\ICommand;
use OCP\Files\StorageNotAvailableException;
@@ -17,8 +16,6 @@
use Psr\Log\LoggerInterface;
class Expire implements ICommand {
- use FileAccess;
-
public function __construct(
private string $user,
private string $fileName,
diff --git a/apps/files_versions/tests/VersioningTest.php b/apps/files_versions/tests/VersioningTest.php
index e0e738bf81237..5a3bb4dc96999 100644
--- a/apps/files_versions/tests/VersioningTest.php
+++ b/apps/files_versions/tests/VersioningTest.php
@@ -24,6 +24,7 @@
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IMimeTypeLoader;
+use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
@@ -337,7 +338,7 @@ public function testRenameInSharedFolder(): void {
$this->rootView->file_put_contents($v1, 'version1');
$this->rootView->file_put_contents($v2, 'version2');
- $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
+ $node = Server::get(IRootFolder::class)->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
$share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
@@ -403,7 +404,7 @@ public function testMoveFileIntoSharedFolderAsRecipient(): void {
Filesystem::mkdir('folder1');
$fileInfo = Filesystem::getFileInfo('folder1');
- $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
+ $node = Server::get(IRootFolder::class)->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
$share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
@@ -453,7 +454,7 @@ public function testMoveFileIntoSharedFolderAsRecipient(): void {
public function testMoveFolderIntoSharedFolderAsRecipient(): void {
Filesystem::mkdir('folder1');
- $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
+ $node = Server::get(IRootFolder::class)->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
$share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
@@ -520,7 +521,7 @@ public function testRenameSharedFile(): void {
$this->rootView->file_put_contents($v1, 'version1');
$this->rootView->file_put_contents($v2, 'version2');
- $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('test.txt');
+ $node = Server::get(IRootFolder::class)->getUserFolder(self::TEST_VERSIONS_USER)->get('test.txt');
$share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
@@ -659,7 +660,7 @@ public function testRestoreCrossStorage(): void {
public function testRestoreNoPermission(): void {
$this->loginAsUser(self::TEST_VERSIONS_USER);
- $userHome = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER);
+ $userHome = Server::get(IRootFolder::class)->getUserFolder(self::TEST_VERSIONS_USER);
$node = $userHome->newFolder('folder');
$file = $node->newFile('test.txt');
@@ -695,11 +696,11 @@ public function testRestoreMovedShare(): void {
$this->markTestSkipped('Unreliable test');
$this->loginAsUser(self::TEST_VERSIONS_USER);
- $userHome = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER);
+ $userHome = Server::get(IRootFolder::class)->getUserFolder(self::TEST_VERSIONS_USER);
$node = $userHome->newFolder('folder');
$file = $node->newFile('test.txt');
- $userHome2 = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER2);
+ $userHome2 = Server::get(IRootFolder::class)->getUserFolder(self::TEST_VERSIONS_USER2);
$userHome2->newFolder('subfolder');
$share = Server::get(\OCP\Share\IManager::class)->newShare();
@@ -900,7 +901,7 @@ public function testStoreVersionAsRecipient(): void {
Filesystem::mkdir('folder');
Filesystem::file_put_contents('folder/test.txt', 'test file');
- $node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder');
+ $node = Server::get(IRootFolder::class)->getUserFolder(self::TEST_VERSIONS_USER)->get('folder');
$share = Server::get(\OCP\Share\IManager::class)->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
@@ -975,7 +976,7 @@ public static function loginHelper(string $user, bool $create = false) {
Filesystem::tearDown();
\OC_User::setUserId($user);
\OC_Util::setupFS($user);
- \OC::$server->getUserFolder($user);
+ Server::get(IRootFolder::class)->getUserFolder($user);
}
}
diff --git a/apps/settings/tests/AppInfo/ApplicationTest.php b/apps/settings/tests/AppInfo/ApplicationTest.php
index a1becb6ffc808..3479f31f4561d 100644
--- a/apps/settings/tests/AppInfo/ApplicationTest.php
+++ b/apps/settings/tests/AppInfo/ApplicationTest.php
@@ -57,6 +57,6 @@ public static function dataContainerQuery(): array {
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataContainerQuery')]
public function testContainerQuery(string $service, string $expected): void {
- $this->assertTrue($this->container->query($service) instanceof $expected);
+ $this->assertTrue($this->container->get($service) instanceof $expected);
}
}
diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
index 040bab095a1fa..3bf1da81921c5 100644
--- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
+++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
@@ -62,7 +62,7 @@ private function execFetchTest($dn, $username, $image) {
// also remove an possibly existing avatar
\OC_Util::tearDownFS();
\OC_Util::setupFS($username);
- \OC::$server->getUserFolder($username);
+ Server::get(IRootFolder::class)->getUserFolder($username);
Server::get(IConfig::class)->deleteUserValue($username, 'user_ldap', User::USER_PREFKEY_LASTREFRESH);
if (Server::get(IAvatarManager::class)->getAvatar($username)->exists()) {
Server::get(IAvatarManager::class)->getAvatar($username)->remove();
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml
index c06c6df854fc4..cad3eaf0da76a 100644
--- a/build/psalm-baseline.xml
+++ b/build/psalm-baseline.xml
@@ -832,9 +832,6 @@
-
-
-
@@ -1043,8 +1040,6 @@
-
-
@@ -1787,9 +1782,6 @@
-
-
-
@@ -1874,8 +1866,6 @@
Filesystem::normalizePath($file_path),
'trashPath' => Filesystem::normalizePath(static::getTrashFilename($filename, $timestamp))])]]>
$targetPath, 'trashPath' => $sourcePath])]]>
-
-
@@ -3782,11 +3772,6 @@
-
-
-
-
-
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index d80e425b285e4..ea379225b5f19 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -717,7 +717,6 @@
'OCP\\IPreview' => $baseDir . '/lib/public/IPreview.php',
'OCP\\IRequest' => $baseDir . '/lib/public/IRequest.php',
'OCP\\IRequestId' => $baseDir . '/lib/public/IRequestId.php',
- 'OCP\\IServerContainer' => $baseDir . '/lib/public/IServerContainer.php',
'OCP\\IServerInfo' => $baseDir . '/lib/public/IServerInfo.php',
'OCP\\ISession' => $baseDir . '/lib/public/ISession.php',
'OCP\\IStreamImage' => $baseDir . '/lib/public/IStreamImage.php',
@@ -1391,7 +1390,6 @@
'OC\\Command\\AsyncBus' => $baseDir . '/lib/private/Command/AsyncBus.php',
'OC\\Command\\CommandJob' => $baseDir . '/lib/private/Command/CommandJob.php',
'OC\\Command\\CronBus' => $baseDir . '/lib/private/Command/CronBus.php',
- 'OC\\Command\\FileAccess' => $baseDir . '/lib/private/Command/FileAccess.php',
'OC\\Command\\QueueBus' => $baseDir . '/lib/private/Command/QueueBus.php',
'OC\\Comments\\Comment' => $baseDir . '/lib/private/Comments/Comment.php',
'OC\\Comments\\Manager' => $baseDir . '/lib/private/Comments/Manager.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index ee95df28b9974..81cf5247bcc5b 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -758,7 +758,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\IPreview' => __DIR__ . '/../../..' . '/lib/public/IPreview.php',
'OCP\\IRequest' => __DIR__ . '/../../..' . '/lib/public/IRequest.php',
'OCP\\IRequestId' => __DIR__ . '/../../..' . '/lib/public/IRequestId.php',
- 'OCP\\IServerContainer' => __DIR__ . '/../../..' . '/lib/public/IServerContainer.php',
'OCP\\IServerInfo' => __DIR__ . '/../../..' . '/lib/public/IServerInfo.php',
'OCP\\ISession' => __DIR__ . '/../../..' . '/lib/public/ISession.php',
'OCP\\IStreamImage' => __DIR__ . '/../../..' . '/lib/public/IStreamImage.php',
@@ -1432,7 +1431,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Command\\AsyncBus' => __DIR__ . '/../../..' . '/lib/private/Command/AsyncBus.php',
'OC\\Command\\CommandJob' => __DIR__ . '/../../..' . '/lib/private/Command/CommandJob.php',
'OC\\Command\\CronBus' => __DIR__ . '/../../..' . '/lib/private/Command/CronBus.php',
- 'OC\\Command\\FileAccess' => __DIR__ . '/../../..' . '/lib/private/Command/FileAccess.php',
'OC\\Command\\QueueBus' => __DIR__ . '/../../..' . '/lib/private/Command/QueueBus.php',
'OC\\Comments\\Comment' => __DIR__ . '/../../..' . '/lib/private/Comments/Comment.php',
'OC\\Comments\\Manager' => __DIR__ . '/../../..' . '/lib/private/Comments/Manager.php',
diff --git a/lib/private/AppFramework/App.php b/lib/private/AppFramework/App.php
index 0503f309ac054..5160fd61c83d7 100644
--- a/lib/private/AppFramework/App.php
+++ b/lib/private/AppFramework/App.php
@@ -168,7 +168,7 @@ public static function main(
$name,
$value['value'],
$expireDate,
- $container->getServer()->getWebRoot(),
+ $container->get('webRoot'),
null,
$container->getServer()->get(IRequest::class)->getServerProtocol() === 'https',
true,
diff --git a/lib/private/AppFramework/Bootstrap/BootContext.php b/lib/private/AppFramework/Bootstrap/BootContext.php
index 82da58ac4bdc2..6551499153b6b 100644
--- a/lib/private/AppFramework/Bootstrap/BootContext.php
+++ b/lib/private/AppFramework/Bootstrap/BootContext.php
@@ -9,12 +9,13 @@
namespace OC\AppFramework\Bootstrap;
+use OC\Server;
use OCP\AppFramework\Bootstrap\IBootContext;
-use OCP\IServerContainer;
use Psr\Container\ContainerInterface;
class BootContext implements IBootContext {
public function __construct(
+ private Server $serverContainer,
private ContainerInterface $appContainer,
) {
}
@@ -26,7 +27,7 @@ public function getAppContainer(): ContainerInterface {
#[\Override]
public function getServerContainer(): ContainerInterface {
- return $this->appContainer->get(IServerContainer::class);
+ return $this->serverContainer;
}
#[\Override]
diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php
index 13e2bc2985e8e..9770c036f777d 100644
--- a/lib/private/AppFramework/Bootstrap/Coordinator.php
+++ b/lib/private/AppFramework/Bootstrap/Coordinator.php
@@ -10,6 +10,7 @@
namespace OC\AppFramework\Bootstrap;
use OC\App\AppManager;
+use OC\Server;
use OC\Support\CrashReport\Registry;
use OCP\App\AppPathNotFoundException;
use OCP\AppFramework\App;
@@ -19,7 +20,6 @@
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use Psr\Container\ContainerExceptionInterface;
-use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Throwable;
use function class_exists;
@@ -34,7 +34,7 @@ class Coordinator {
private array $bootedApps = [];
public function __construct(
- private ContainerInterface $serverContainer,
+ private Server $serverContainer,
private Registry $registry,
private IManager $dashboardManager,
private IEventDispatcher $eventDispatcher,
@@ -162,7 +162,7 @@ public function bootApp(string $appId): void {
try {
$application = $this->serverContainer->get($applicationClassName);
if ($application instanceof IBootstrap && $application instanceof App) {
- $context = new BootContext($application->getContainer());
+ $context = new BootContext($this->serverContainer, $application->getContainer());
$application->boot($context);
}
} catch (QueryException $e) {
diff --git a/lib/private/AppFramework/DependencyInjection/DIContainer.php b/lib/private/AppFramework/DependencyInjection/DIContainer.php
index 628038ee45c07..f5680374add02 100644
--- a/lib/private/AppFramework/DependencyInjection/DIContainer.php
+++ b/lib/private/AppFramework/DependencyInjection/DIContainer.php
@@ -39,7 +39,7 @@
use OC\Core\Middleware\TwoFactorMiddleware;
use OC\Diagnostics\EventLogger;
use OC\Log\PsrLoggerAdapter;
-use OC\ServerContainer;
+use OC\Server;
use OC\Settings\AuthorizedGroupMapper;
use OC\User\Session;
use OCA\WorkflowEngine\Manager;
@@ -60,25 +60,23 @@
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IRequest;
-use OCP\IServerContainer;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Security\Ip\IRemoteAddress;
-use OCP\Server;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
class DIContainer extends SimpleContainer implements IAppContainer {
private array $middleWares = [];
- private ServerContainer $server;
+ private Server $server;
private IAppManager $appManager;
public function __construct(
protected string $appName,
array $urlParams = [],
- ?ServerContainer $server = null,
+ ?Server $server = null,
) {
parent::__construct();
$this->registerParameter('appName', $this->appName);
@@ -133,11 +131,9 @@ public function __construct(
);
});
- $this->registerService(IServerContainer::class, function () {
+ $this->registerService(Server::class, function () {
return $this->getServer();
});
- /** @deprecated 32.0.0 */
- $this->registerDeprecatedAlias('ServerContainer', IServerContainer::class);
$this->registerAlias(\OCP\WorkflowEngine\IManager::class, Manager::class);
@@ -149,12 +145,10 @@ public function __construct(
return $c->get(ISession::class)->get('user_id');
});
- $this->registerService('webRoot', function (ContainerInterface $c): string {
- return $c->get(IServerContainer::class)->getWebRoot();
- });
+ $this->registerParameter('webRoot', $this->server->getWebRoot());
$this->registerService('OC_Defaults', function (ContainerInterface $c): object {
- return $c->get(IServerContainer::class)->get('ThemingDefaults');
+ return $this->server->get('ThemingDefaults');
});
/** @deprecated 32.0.0 */
@@ -255,7 +249,7 @@ public function __construct(
}
#[\Override]
- public function getServer(): ServerContainer {
+ public function getServer(): Server {
return $this->server;
}
@@ -280,23 +274,6 @@ public function getAppName() {
return $this->query('appName');
}
- /**
- * @deprecated 12.0.0 use IUserSession->isLoggedIn()
- * @return boolean
- */
- public function isLoggedIn() {
- return Server::get(IUserSession::class)->isLoggedIn();
- }
-
- /**
- * @deprecated 12.0.0 use IGroupManager->isAdmin($userId)
- * @return boolean
- */
- public function isAdminUser() {
- $uid = $this->getUserId();
- return \OC_User::isAdminUser($uid);
- }
-
private function getUserId(): string {
return $this->getServer()->get(Session::class)->getSession()->get('user_id');
}
@@ -331,25 +308,21 @@ public function has($id): bool {
* @param list $chain
*/
#[\Override]
- public function query(string $name, bool $autoload = true, array $chain = []): mixed {
+ protected function query(string $name, bool $autoload = true, array $chain = []): mixed {
if ($name === 'AppName' || $name === 'appName') {
return $this->appName;
}
$isServerClass = str_starts_with($name, 'OCP\\') || str_starts_with($name, 'OC\\');
if ($isServerClass && !$this->has($name)) {
- /** @var ServerContainer $server */
- $server = $this->getServer();
- return $server->query($name, $autoload, $chain);
+ return $this->server->query($name, $autoload, $chain);
}
try {
return $this->queryNoFallback($name, $chain);
} catch (QueryException $firstException) {
try {
- /** @var ServerContainer $server */
- $server = $this->getServer();
- return $server->query($name, $autoload, $chain);
+ return $this->server->query($name, $autoload, $chain);
} catch (QueryException $secondException) {
if ($firstException->getCode() === 1) {
throw $secondException;
@@ -360,20 +333,17 @@ public function query(string $name, bool $autoload = true, array $chain = []): m
}
/**
- * @param string $name
+ * @param string already sanitized $name
* @param list $chain
* @return mixed
* @throws QueryException if the query could not be resolved
+ * @internal
*/
public function queryNoFallback($name, array $chain) {
- $name = $this->sanitizeName($name);
-
- if ($this->offsetExists($name)) {
- return parent::query($name, chain: $chain);
+ if (isset($this->container[$name])) {
+ return $this->container[$name];
} elseif ($this->appName === 'settings' && str_starts_with($name, 'OC\\Settings\\')) {
return parent::query($name, chain: $chain);
- } elseif ($this->appName === 'core' && str_starts_with($name, 'OC\\Core\\')) {
- return parent::query($name, chain: $chain);
} elseif (str_starts_with($name, $this->appManager->getAppNamespace($this->appName) . '\\')) {
return parent::query($name, chain: $chain);
} elseif (
diff --git a/lib/private/AppFramework/Utility/SimpleContainer.php b/lib/private/AppFramework/Utility/SimpleContainer.php
index e23e34dcc5ea1..9d137117ef8f7 100644
--- a/lib/private/AppFramework/Utility/SimpleContainer.php
+++ b/lib/private/AppFramework/Utility/SimpleContainer.php
@@ -30,7 +30,7 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer {
/** @psalm-suppress ImpureStaticProperty A static property is the only way to pass the information from config to autoload */
public static bool $useLazyObjects = false;
- private Container $container;
+ protected Container $container;
public function __construct() {
$this->container = new Container();
@@ -43,7 +43,7 @@ public function __construct() {
*/
#[\Override]
public function get(string $id): mixed {
- return $this->query($id);
+ return $this->query($this->sanitizeName($id));
}
#[\Override]
@@ -121,10 +121,16 @@ private function buildClassConstructorParameters(\ReflectionMethod $constructor,
}
/**
- * @inheritDoc
+ * @template T
+ *
+ * Try to instantiate by using reflection to find out how to build the class.
+ *
+ * @param class-string|string $name
* @param list $chain
+ * @return ($name is class-string ? T : mixed)
+ * @internal
+ * @throws ContainerExceptionInterface if the class could not be found or instantiated
*/
- #[\Override]
public function resolve(string $name, array $chain = []): mixed {
$baseMsg = 'Could not resolve ' . $name . '!';
try {
@@ -142,41 +148,49 @@ public function resolve(string $name, array $chain = []): mixed {
}
/**
- * @inheritDoc
+ * @param string $name Already sanitized name
* @param list $chain
*/
- #[\Override]
- public function query(string $name, bool $autoload = true, array $chain = []): mixed {
- $name = $this->sanitizeName($name);
+ protected function query(string $name, bool $autoload = true, array $chain = []): mixed {
if (isset($this->container[$name])) {
return $this->container[$name];
}
- if ($autoload) {
- if (in_array($name, $chain, true)) {
- throw new RuntimeException('Tried to query ' . $name . ', but it is already in the chain: ' . implode(', ', $chain));
- }
+ if (!$autoload) {
+ throw new QueryNotFoundException('Could not resolve ' . $name . '!');
+ }
- $object = $this->resolve($name, array_merge($chain, [$name]));
- $this->registerService($name, function () use ($object) {
- return $object;
- });
- return $object;
+ if (in_array($name, $chain, true)) {
+ throw new RuntimeException('Tried to query ' . $name . ', but it is already in the chain: ' . implode(', ', $chain));
}
- throw new QueryNotFoundException('Could not resolve ' . $name . '!');
+ $object = $this->resolve($name, array_merge($chain, [$name]));
+ $this->registerService($name, static fn () => $object);
+ return $object;
}
- #[\Override]
+ /**
+ * A value is stored in the container with its corresponding name
+ *
+ * @since 6.0.0
+ * @internal apps should use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerParameter
+ */
public function registerParameter(string $name, mixed $value): void {
- $this[$name] = $value;
+ $this->container[$name] = $value;
}
- #[\Override]
+ /**
+ * A service is registered in the container where a closure is passed in which will actually
+ * create the service on demand.
+ * In case the parameter $shared is set to true (the default usage) the once created service will remain in
+ * memory and be reused on subsequent calls.
+ * In case the parameter is false the service will be recreated on every call.
+ *
+ * @param \Closure(IContainer): mixed $closure
+ * @internal apps should use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerService
+ */
public function registerService(string $name, Closure $closure, bool $shared = true): void {
- $wrapped = function () use ($closure) {
- return $closure($this);
- };
+ $wrapped = fn () => $closure($this);
$name = $this->sanitizeName($name);
if (isset($this->container[$name])) {
unset($this->container[$name]);
@@ -195,11 +209,12 @@ public function registerService(string $name, Closure $closure, bool $shared = t
* @param string $alias the alias that should be registered
* @param string $target the target that should be resolved instead
*/
- #[\Override]
public function registerAlias(string $alias, string $target): void {
- $this->registerService($alias, function (ContainerInterface $container) use ($target): mixed {
- return $container->get($target);
- }, false);
+ $this->registerService(
+ $alias,
+ static fn (ContainerInterface $container): mixed => $container->get($target),
+ false,
+ );
}
protected function registerDeprecatedAlias(string $alias, string $target): void {
diff --git a/lib/private/Collaboration/Collaborators/Search.php b/lib/private/Collaboration/Collaborators/Search.php
index c391d22af7234..0114eae2d62da 100644
--- a/lib/private/Collaboration/Collaborators/Search.php
+++ b/lib/private/Collaboration/Collaborators/Search.php
@@ -39,8 +39,7 @@ public function filteredSearch(string $search, array $shareTypes, bool $lookup,
// Trim leading and trailing whitespace characters, e.g. when query is copy-pasted
$search = trim($search);
- /** @var ISearchResult $searchResult */
- $searchResult = $this->container->resolve(SearchResult::class);
+ $searchResult = new SearchResult();
foreach ($shareTypes as $type) {
if (!isset($this->pluginList[$type])) {
diff --git a/lib/private/Command/FileAccess.php b/lib/private/Command/FileAccess.php
deleted file mode 100644
index a8deeac359e83..0000000000000
--- a/lib/private/Command/FileAccess.php
+++ /dev/null
@@ -1,22 +0,0 @@
-getUID());
- }
-
- protected function getUserFolder(IUser $user) {
- $this->setupFS($user);
- return \OC::$server->getUserFolder($user->getUID());
- }
-}
diff --git a/lib/private/Files/Config/CachedMountInfo.php b/lib/private/Files/Config/CachedMountInfo.php
index c46e5f9fb660d..9968529dfeb22 100644
--- a/lib/private/Files/Config/CachedMountInfo.php
+++ b/lib/private/Files/Config/CachedMountInfo.php
@@ -10,8 +10,10 @@
use OC\Files\Filesystem;
use OCP\Files\Config\ICachedMountInfo;
+use OCP\Files\IRootFolder;
use OCP\Files\Node;
use OCP\IUser;
+use OCP\Server;
class CachedMountInfo implements ICachedMountInfo {
protected string $key;
@@ -59,8 +61,8 @@ public function getRootId(): int {
public function getMountPointNode(): ?Node {
// TODO injection etc
Filesystem::initMountPoints($this->getUser()->getUID());
- $userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
- return $userNode->getParent()->getFirstNodeById($this->getRootId());
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder($this->getUser()->getUID());
+ return $userFolder->getParent()->getFirstNodeById($this->getRootId());
}
/**
diff --git a/lib/private/InitialStateService.php b/lib/private/InitialStateService.php
index e00f755502105..ed9d214982a58 100644
--- a/lib/private/InitialStateService.php
+++ b/lib/private/InitialStateService.php
@@ -94,7 +94,7 @@ private function loadLazyStates(): void {
$initialStates = $context->getInitialStates();
foreach ($initialStates as $initialState) {
try {
- $provider = $this->container->query($initialState->getService());
+ $provider = $this->container->get($initialState->getService());
} catch (QueryException $e) {
// Log an continue. We can be fault tolerant here.
$this->logger->error('Could not load initial state provider dynamically: ' . $e->getMessage(), [
diff --git a/lib/private/Server.php b/lib/private/Server.php
index f2d5c731f3f70..00dec09171c65 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -196,7 +196,6 @@
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Conversion\IConversionManager;
-use OCP\Files\Folder;
use OCP\Files\IFilenameValidator;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\IMimeTypeLoader;
@@ -225,13 +224,11 @@
use OCP\IEventSourceFactory;
use OCP\IGroupManager;
use OCP\IInitialStateService;
-use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IPhoneNumberUtil;
use OCP\IPreview;
use OCP\IRequest;
use OCP\IRequestId;
-use OCP\IServerContainer;
use OCP\IServerInfo;
use OCP\ISession;
use OCP\ITagManager;
@@ -306,7 +303,7 @@
*
* TODO: hookup all manager classes
*/
-class Server extends ServerContainer implements IServerContainer {
+class Server extends ServerContainer {
public function __construct(
private string $webRoot,
Config $config,
@@ -316,14 +313,14 @@ public function __construct(
// To find out if we are running from CLI or not
$this->registerParameter('isCLI', \OC::$CLI);
$this->registerParameter('serverRoot', \OC::$SERVERROOT);
- $this->registerService('userId', function (ContainerInterface $c): ?string {
+ $this->registerService('userId', static function (ContainerInterface $c): ?string {
return $c->get(ISession::class)->get('user_id');
});
- $this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
- return $c;
+ $this->registerService(self::class, function (ContainerInterface $c) {
+ return $this;
});
- $this->registerDeprecatedAlias(IServerContainer::class, ContainerInterface::class);
+ $this->registerService(ContainerInterface::class, static fn (ContainerInterface $c) => $c);
$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
@@ -342,15 +339,13 @@ public function __construct(
$this->registerAlias(IActionFactory::class, ActionFactory::class);
- $this->registerService(View::class, function (Server $c) {
- return new View();
- }, false);
+ $this->registerService(View::class, static fn (ContainerInterface $c) => new View(), false);
$this->registerAlias(IPreview::class, PreviewManager::class);
$this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class);
$this->registerAlias(IProfiler::class, Profiler::class);
- $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager {
+ $this->registerService(Encryption\Manager::class, static function (Server $c): Encryption\Manager {
return new Encryption\Manager(
$c->get(IConfig::class),
$c->get(LoggerInterface::class),
@@ -371,10 +366,10 @@ public function __construct(
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
- $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
+ $this->registerService(ISystemTagManager::class, static function (ContainerInterface $c) {
return $c->get(ISystemTagManagerFactory::class)->getManager();
});
- $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
+ $this->registerService(ISystemTagObjectMapper::class, static function (ContainerInterface $c) {
return $c->get(ISystemTagManagerFactory::class)->getObjectMapper();
});
@@ -411,13 +406,13 @@ public function __construct(
$this->registerAlias(IUserManager::class, \OC\User\Manager::class);
- $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) {
+ $this->registerService(DisplayNameCache::class, static function (ContainerInterface $c) {
return $c->get(\OC\User\Manager::class)->getDisplayNameCache();
});
$this->registerAlias(IGroupManager::class, \OC\Group\Manager::class);
- $this->registerService(Store::class, function (ContainerInterface $c) {
+ $this->registerService(Store::class, static function (ContainerInterface $c) {
$session = $c->get(ISession::class);
if (\OCP\Server::get(SystemConfig::class)->getValue('installed', false)) {
$tokenProvider = $c->get(IProvider::class);
@@ -536,9 +531,7 @@ public function __construct(
$this->registerAlias(IConfig::class, AllConfig::class);
- $this->registerService(SystemConfig::class, function ($c) use ($config) {
- return new SystemConfig($config);
- });
+ $this->registerService(SystemConfig::class, static fn ($c) => new SystemConfig($config));
$this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
$this->registerAlias(IUserConfig::class, UserConfig::class);
@@ -549,7 +542,7 @@ public function __construct(
$this->registerAlias(IURLGenerator::class, URLGenerator::class);
$this->registerAlias(ICache::class, Cache\File::class);
- $this->registerService(Factory::class, function (Server $c) {
+ $this->registerService(Factory::class, static function (Server $c) {
$profiler = $c->get(IProfiler::class);
$logger = $c->get(LoggerInterface::class);
$serverVersion = $c->get(ServerVersion::class);
@@ -584,8 +577,8 @@ public function __construct(
$this->registerDeprecatedAlias('RedisFactory', RedisFactory::class);
- $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
- $l10n = $this->get(IFactory::class)->get('lib');
+ $this->registerService(\OCP\Activity\IManager::class, static function (Server $c) {
+ $l10n = $c->get(IFactory::class)->get('lib');
return new \OC\Activity\Manager(
$c->get(IRequest::class),
$c->get(IUserSession::class),
@@ -600,7 +593,7 @@ public function __construct(
$this->registerAlias(IEventMerger::class, EventMerger::class);
$this->registerAlias(IValidator::class, Validator::class);
- $this->registerService(AvatarManager::class, function (Server $c) {
+ $this->registerService(AvatarManager::class, static function (Server $c) {
return new AvatarManager(
$c->get(IUserSession::class),
$c->get(\OC\User\Manager::class),
@@ -621,13 +614,14 @@ public function __construct(
$this->registerAlias(IAssertion::class, Assertion::class);
/** Only used by the PsrLoggerAdapter should not be used by apps */
- $this->registerService(Log::class, function (Server $c) {
+ $this->registerService(Log::class, static function (Server $c) {
+ $systemConfig = $c->get(SystemConfig::class);
$logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
- $factory = new LogFactory($c, $this->get(SystemConfig::class), $c->get('serverRoot'));
+ $factory = new LogFactory($c, $systemConfig, $c->get('serverRoot'));
$logger = $factory->get($logType);
$registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
- return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry);
+ return new Log($logger, $systemConfig, crashReporters: $registry);
});
// PSR-3 logger
$this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
@@ -635,7 +629,7 @@ public function __construct(
$this->registerAlias(ILogFactory::class, LogFactory::class);
$this->registerAlias(IJobList::class, JobList::class);
- $this->registerService(Router::class, function (Server $c) {
+ $this->registerService(Router::class, static function (Server $c) {
$cacheFactory = $c->get(ICacheFactory::class);
if ($cacheFactory->isLocalCacheAvailable()) {
$router = $c->resolve(CachingRouter::class);
@@ -646,12 +640,12 @@ public function __construct(
});
$this->registerAlias(IRouter::class, Router::class);
- $this->registerService(IBackend::class, function ($c): IBackend {
+ $this->registerService(IBackend::class, static function ($c): IBackend {
$config = $c->get(IConfig::class);
if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === Redis::class) {
$backend = new MemoryCacheBackend(
$c->get(AllConfig::class),
- $this->get(ICacheFactory::class),
+ $c->get(ICacheFactory::class),
new TimeFactory()
);
} else {
@@ -676,7 +670,7 @@ public function __construct(
$this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
$this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
- $this->registerService(Connection::class, function (Server $c) {
+ $this->registerService(Connection::class, static function (Server $c) {
$systemConfig = $c->get(SystemConfig::class);
$factory = new ConnectionFactory($systemConfig, $c->get(ICacheFactory::class));
$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -690,15 +684,13 @@ public function __construct(
$this->registerAlias(ICertificateManager::class, CertificateManager::class);
$this->registerAlias(IClientService::class, ClientService::class);
$this->registerDeprecatedAlias('HttpClientService', IClientService::class);
- $this->registerService(IEventLogger::class, function (ContainerInterface $c) {
- return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class));
- });
+ $this->registerAlias(IEventLogger::class, EventLogger::class);
$this->registerAlias(IQueryLogger::class, QueryLogger::class);
$this->registerAlias(ITempManager::class, TempManager::class);
$this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
- $this->registerService(IDateTimeFormatter::class, function (Server $c) {
+ $this->registerService(IDateTimeFormatter::class, static function (Server $c) {
$language = $c->get(IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
return new DateTimeFormatter(
@@ -707,14 +699,14 @@ public function __construct(
);
});
- $this->registerService(IUserMountCache::class, function (ContainerInterface $c): IUserMountCache {
+ $this->registerService(IUserMountCache::class, static function (ContainerInterface $c): IUserMountCache {
$mountCache = $c->get(UserMountCache::class);
$listener = new UserMountCacheListener($mountCache);
$listener->listen($c->get(IUserManager::class));
return $mountCache;
});
- $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c): IMountProviderCollection {
+ $this->registerService(IMountProviderCollection::class, static function (ContainerInterface $c): IMountProviderCollection {
$loader = $c->get(IStorageFactory::class);
$mountCache = $c->get(IUserMountCache::class);
$eventLogger = $c->get(IEventLogger::class);
@@ -732,7 +724,7 @@ public function __construct(
return $manager;
});
- $this->registerService(IBus::class, function (ContainerInterface $c): IBus {
+ $this->registerService(IBus::class, static function (ContainerInterface $c): IBus {
$busClass = $c->get(IConfig::class)->getSystemValueString('commandbus');
if ($busClass) {
[$app, $class] = explode('::', $busClass, 2);
@@ -751,7 +743,7 @@ public function __construct(
$this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class);
$this->registerAlias(IThrottler::class, Throttler::class);
- $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, function ($c) {
+ $this->registerService(\OC\Security\Bruteforce\Backend\IBackend::class, static function ($c) {
$config = $c->get(IConfig::class);
if (!$config->getSystemValueBool('auth.bruteforce.protection.force.database', false)
&& ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === Redis::class) {
@@ -764,7 +756,7 @@ public function __construct(
});
$this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class);
- $this->registerService(Checker::class, function (ContainerInterface $c) {
+ $this->registerService(Checker::class, static function (ContainerInterface $c) {
// IConfig requires a working database. This code
// might however be called when Nextcloud is not yet setup.
if (\OCP\Server::get(SystemConfig::class)->getValue('installed', false)) {
@@ -822,17 +814,17 @@ public function __construct(
});
$this->registerAlias(IRequest::class, Request::class);
- $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId {
+ $this->registerService(IRequestId::class, static function (ContainerInterface $c): IRequestId {
return new RequestId(
$_SERVER['UNIQUE_ID'] ?? '',
- $this->get(ISecureRandom::class)
+ $c->get(ISecureRandom::class)
);
});
/** @since 32.0.0 */
$this->registerAlias(IEmailValidator::class, EmailValidator::class);
- $this->registerService(IMailer::class, function (Server $c) {
+ $this->registerService(IMailer::class, static function (Server $c) {
return new Mailer(
$c->get(IConfig::class),
$c->get(LoggerInterface::class),
@@ -848,20 +840,20 @@ public function __construct(
/** @since 30.0.0 */
$this->registerAlias(\OCP\Mail\Provider\IManager::class, \OC\Mail\Provider\Manager::class);
- $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
+ $this->registerService(ILDAPProviderFactory::class, static function (ContainerInterface $c) {
$config = $c->get(IConfig::class);
$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
if (is_null($factoryClass) || !class_exists($factoryClass)) {
- return new NullLDAPProviderFactory($this);
+ return new NullLDAPProviderFactory($c);
}
/** @var ILDAPProviderFactory $factory */
- return new $factoryClass($this);
+ return new $factoryClass($c);
});
- $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
+ $this->registerService(ILDAPProvider::class, static function (ContainerInterface $c) {
$factory = $c->get(ILDAPProviderFactory::class);
return $factory->getLDAPProvider();
});
- $this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
+ $this->registerService(ILockingProvider::class, static function (ContainerInterface $c) {
$ini = $c->get(IniGetWrapper::class);
$config = $c->get(IConfig::class);
$ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, (int)($ini->getNumeric('max_execution_time') ?? 0)));
@@ -885,13 +877,13 @@ public function __construct(
$this->registerAlias(ILockManager::class, LockManager::class);
- $this->registerService(SetupManager::class, function ($c) {
+ $this->registerService(SetupManager::class, static function ($c) {
// create the setupmanager through the mount manager to resolve the cyclic dependency
return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager();
});
$this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
- $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
+ $this->registerService(IMimeTypeDetector::class, static function (ContainerInterface $c) {
return new Detection(
$c->get(IURLGenerator::class),
$c->get(LoggerInterface::class),
@@ -903,22 +895,22 @@ public function __construct(
$this->registerAlias(IMimeTypeLoader::class, Loader::class);
$this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
- $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
+ $this->registerService(CapabilitiesManager::class, static function (ContainerInterface $c) {
$manager = new CapabilitiesManager($c->get(LoggerInterface::class));
- $manager->registerCapability(function () use ($c) {
+ $manager->registerCapability(static function () use ($c) {
return new CoreCapabilities($c->get(IConfig::class));
});
- $manager->registerCapability(function () use ($c) {
+ $manager->registerCapability(static function () use ($c) {
return $c->get(Capabilities::class);
});
return $manager;
});
- $this->registerService(ICommentsManager::class, function (Server $c) {
+ $this->registerService(ICommentsManager::class, static function (Server $c) {
$config = $c->get(IConfig::class);
$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
/** @var ICommentsManagerFactory $factory */
- $factory = new $factoryClass($this);
+ $factory = new $factoryClass($c);
$manager = $factory->getManager();
$manager->registerDisplayNameResolver('user', function ($id) use ($c) {
@@ -935,7 +927,7 @@ public function __construct(
});
$this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
- $this->registerService('ThemingDefaults', function (Server $c) {
+ $this->registerService('ThemingDefaults', static function (Server $c) {
try {
$classExists = class_exists('OCA\Theming\ThemingDefaults');
} catch (AutoloadNotAllowedException $e) {
@@ -982,7 +974,7 @@ public function __construct(
new Util(
$c->get(ServerVersion::class),
$c->get(IConfig::class),
- $this->get(IAppManager::class),
+ $c->get(IAppManager::class),
$c->get(IAppDataFactory::class)->get('theming'),
$imageManager,
),
@@ -994,11 +986,11 @@ public function __construct(
}
return new \OC_Defaults();
});
- $this->registerService(JSCombiner::class, function (Server $c) {
+ $this->registerService(JSCombiner::class, static function (Server $c) {
return new JSCombiner(
$c->get(IAppDataFactory::class)->get('js'),
$c->get(IURLGenerator::class),
- $this->get(ICacheFactory::class),
+ $c->get(ICacheFactory::class),
$c->get(IConfig::class),
$c->get(LoggerInterface::class)
);
@@ -1007,7 +999,7 @@ public function __construct(
/** @deprecated 35.0.0 */
$this->registerDeprecatedAlias('CryptoWrapper', CryptoWrapper::class);
- $this->registerService(CryptoWrapper::class, function (ContainerInterface $c): CryptoWrapper {
+ $this->registerService(CryptoWrapper::class, static function (ContainerInterface $c): CryptoWrapper {
// FIXME: Instantiated here due to cyclic dependency
$request = new Request(
[
@@ -1033,7 +1025,7 @@ public function __construct(
});
$this->registerAlias(IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
- $this->registerService(IProviderFactory::class, function (ContainerInterface $c) {
+ $this->registerService(IProviderFactory::class, static function (ContainerInterface $c) {
$config = $c->get(IConfig::class);
$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
/** @var IProviderFactory $factory */
@@ -1042,7 +1034,7 @@ public function __construct(
$this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
- $this->registerService(ISearch::class, function (Server $c): ISearch {
+ $this->registerService(ISearch::class, static function (Server $c): ISearch {
$instance = new Search($c, $c->get(IEventDispatcher::class));
// register default plugins
@@ -1070,12 +1062,8 @@ public function __construct(
/** @deprecated 35.0.0 */
$this->registerDeprecatedAlias('LockdownManager', ILockdownManager::class);
- $this->registerService(LockdownManager::class, function (ContainerInterface $c): LockdownManager {
- return new LockdownManager(
- function () use ($c) {
- return $c->get(ISession::class);
- }
- );
+ $this->registerService(LockdownManager::class, static function (ContainerInterface $c): LockdownManager {
+ return new LockdownManager(static fn () => $c->get(ISession::class));
});
$this->registerAlias(ILockdownManager::class, LockdownManager::class);
$this->registerAlias(IDiscoveryService::class, DiscoveryService::class);
@@ -1090,13 +1078,13 @@ function () use ($c) {
$this->registerAlias(ITimeFactory::class, TimeFactory::class);
$this->registerAlias(\Psr\Clock\ClockInterface::class, ITimeFactory::class);
- $this->registerService(Defaults::class, function (Server $c) {
+ $this->registerService(Defaults::class, static function (Server $c) {
return new Defaults(
$c->get('ThemingDefaults')
);
});
- $this->registerService(ISession::class, function (ContainerInterface $c) {
+ $this->registerService(ISession::class, static function (ContainerInterface $c) {
/** @var Session $session */
$session = $c->get(IUserSession::class);
return $session->getSession();
@@ -1144,7 +1132,7 @@ function () use ($c) {
$this->registerAlias(ISnowflakeDecoder::class, SnowflakeDecoder::class);
$this->registerAlias(IJobRuns::class, JobRuns::class);
- $this->registerService(ISequence::class, function (ContainerInterface $c): ISequence {
+ $this->registerService(ISequence::class, static function (ContainerInterface $c): ISequence {
if (PHP_SAPI !== 'cli') {
$sequence = $c->get(APCuSequence::class);
if ($sequence->isAvailable()) {
@@ -1162,7 +1150,7 @@ function () use ($c) {
$this->registerAlias(\NCU\Sharing\ISharingManager::class, SharingManager::class);
$this->registerAlias(\NCU\Sharing\ISharingBackend::class, SharingBackend::class);
- $this->registerService(IGlobalScaleService::class, function (ContainerInterface $c): IGlobalScaleService {
+ $this->registerService(IGlobalScaleService::class, static function (ContainerInterface $c): IGlobalScaleService {
/** @var Coordinator $coordinator */
$coordinator = $c->get(Coordinator::class);
$registrationContext = $coordinator->getRegistrationContext();
@@ -1194,53 +1182,13 @@ private function connectDispatcher(): void {
GenerateBlurhashMetadata::loadListeners($eventDispatcher);
}
- /**
- * Returns a view to ownCloud's files folder
- *
- * @param string $userId user ID
- * @return Folder|null
- * @deprecated 20.0.0
- */
- #[\Override]
- public function getUserFolder($userId = null): ?Folder {
- if ($userId === null) {
- $user = $this->get(IUserSession::class)->getUser();
- if (!$user) {
- return null;
- }
- $userId = $user->getUID();
- }
- $root = $this->get(IRootFolder::class);
- return $root->getUserFolder($userId);
- }
-
public function setSession(ISession $session): void {
$this->get(SessionStorage::class)->setSession($session);
$this->get(Session::class)->setSession($session);
$this->get(Store::class)->setSession($session);
}
- /**
- * Get the webroot
- *
- * @return string
- * @deprecated 20.0.0
- */
- #[\Override]
public function getWebRoot(): string {
return $this->webRoot;
}
-
- /**
- * get an L10N instance
- *
- * @param string $app appid
- * @param string $lang
- * @return IL10N
- * @deprecated 20.0.0 use DI of {@see IL10N} or {@see IFactory} instead, or {@see \OCP\Util::getL10N()} as a last resort
- */
- #[\Override]
- public function getL10N($app, $lang = null) {
- return $this->get(IFactory::class)->get($app, $lang);
- }
}
diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php
index 94e2ce13f16a0..4c345e132b4cc 100644
--- a/lib/private/ServerContainer.php
+++ b/lib/private/ServerContainer.php
@@ -120,19 +120,15 @@ public function has($id, bool $noRecursion = false): bool {
* @psalm-param S $name
* @psalm-return (S is class-string ? T : mixed)
* @throws QueryException
- * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
*/
#[\Override]
- public function query(string $name, bool $autoload = true, array $chain = []): mixed {
- $name = $this->sanitizeName($name);
-
+ protected function query(string $name, bool $autoload = true, array $chain = []): mixed {
if (str_starts_with($name, 'OCA\\')) {
// Skip server container query for app namespace classes
- try {
- return parent::query($name, false, $chain);
- } catch (QueryException $e) {
- // Continue with general autoloading then
+ if (isset($this->container[$name])) {
+ return $this->container[$name];
}
+ // Continue with general autoloading
// In case the service starts with OCA\ we try to find the service in
// the apps container first.
if (($appContainer = $this->getAppContainerForService($name)) !== null) {
@@ -167,8 +163,4 @@ public function getAppContainerForService(string $id): ?DIContainer {
return null;
}
}
-
- public function getWebRoot() {
- return '';
- }
}
diff --git a/lib/private/legacy/OC_User.php b/lib/private/legacy/OC_User.php
index 06255371ff6f1..58bbc57d321a6 100644
--- a/lib/private/legacy/OC_User.php
+++ b/lib/private/legacy/OC_User.php
@@ -17,6 +17,7 @@
use OCP\Authentication\IProvideUserSecretBackend;
use OCP\Authentication\Token\IToken;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\IRootFolder;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\ISession;
@@ -213,7 +214,7 @@ public static function loginWithApache(IApacheBackend $backend): bool {
);
//trigger creation of user home and /files folder
- \OC::$server->getUserFolder($uid);
+ Server::get(IRootFolder::class)->getUserFolder($uid);
}
return true;
}
diff --git a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
index 31ba916358393..9d3f8ef8577fb 100644
--- a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
+++ b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
@@ -80,14 +80,13 @@ public function registerDashboardWidget(string $widgetClass): void;
public function registerService(string $name, callable $factory, bool $shared = true): void;
/**
- * @param string $alias
+ * Shortcut for returning a service from a service under a different key,
+ * e.g. to tell the container to return a class when queried for an
+ * interface
+ *
* @psalm-param string|class-string $alias
- * @param string $target
* @psalm-param string|class-string $target
*
- * @return void
- * @see IContainer::registerAlias()
- *
* @since 20.0.0
*/
public function registerServiceAlias(string $alias, string $target): void;
diff --git a/lib/public/IContainer.php b/lib/public/IContainer.php
index dc1c872f4aa84..a09417d54efbc 100644
--- a/lib/public/IContainer.php
+++ b/lib/public/IContainer.php
@@ -12,7 +12,6 @@
namespace OCP;
-use Closure;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
@@ -39,63 +38,4 @@ interface IContainer extends ContainerInterface {
*/
#[\Override]
public function get(string $id);
-
- /**
- * @template T
- *
- * If a parameter is not registered in the container try to instantiate it
- * by using reflection to find out how to build the class
- * @param class-string|string $name
- * @return ($name is class-string ? T : mixed)
- * @since 8.2.0
- * @deprecated 20.0.0 use {@see self::get()}
- * @throws ContainerExceptionInterface if the class could not be found or instantiated
- */
- public function resolve(string $name): mixed;
-
- /**
- * Look up a service for a given name in the container.
- *
- * @template T
- * @param class-string|string $name
- * @param bool $autoload Should we try to autoload the service. If we are trying to resolve built in types this makes no sense for example
- * @return ($name is class-string ? T : mixed)
- * @throws ContainerExceptionInterface if the query could not be resolved
- * @throws NotFoundExceptionInterface if the name could not be found within the container
- * @since 6.0.0
- * @deprecated 20.0.0 use {@see self::get()}
- */
- public function query(string $name, bool $autoload = true): mixed;
-
- /**
- * A value is stored in the container with it's corresponding name
- *
- * @since 6.0.0
- * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerParameter
- */
- public function registerParameter(string $name, mixed $value): void;
-
- /**
- * A service is registered in the container where a closure is passed in which will actually
- * create the service on demand.
- * In case the parameter $shared is set to true (the default usage) the once created service will remain in
- * memory and be reused on subsequent calls.
- * In case the parameter is false the service will be recreated on every call.
- *
- * @param \Closure(IContainer): mixed $closure
- * @since 6.0.0
- * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerService
- */
- public function registerService(string $name, Closure $closure, bool $shared = true): void;
-
- /**
- * Shortcut for returning a service from a service under a different key,
- * e.g. to tell the container to return a class when queried for an
- * interface
- * @param string $alias the alias that should be registered
- * @param string $target the target that should be resolved instead
- * @since 8.2.0
- * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerServiceAlias
- */
- public function registerAlias(string $alias, string $target): void;
}
diff --git a/lib/public/IServerContainer.php b/lib/public/IServerContainer.php
deleted file mode 100644
index 64e559667982c..0000000000000
--- a/lib/public/IServerContainer.php
+++ /dev/null
@@ -1,57 +0,0 @@
-server = $this->createMock(Server::class);
$this->appContainer = $this->createMock(IAppContainer::class);
$this->context = new BootContext(
- $this->appContainer
+ $this->server,
+ $this->appContainer,
);
}
@@ -38,13 +41,8 @@ public function testGetAppContainer(): void {
}
public function testGetServerContainer(): void {
- $serverContainer = $this->createMock(IServerContainer::class);
- $this->appContainer->method('get')
- ->with(IServerContainer::class)
- ->willReturn($serverContainer);
-
$container = $this->context->getServerContainer();
- $this->assertSame($serverContainer, $container);
+ $this->assertSame($this->server, $container);
}
}
diff --git a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php
index f1f9b2e283470..b9b82235bda4d 100644
--- a/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php
+++ b/tests/lib/AppFramework/Bootstrap/CoordinatorTest.php
@@ -11,6 +11,7 @@
use OC\App\AppManager;
use OC\AppFramework\Bootstrap\Coordinator;
+use OC\Server;
use OC\Support\CrashReport\Registry;
use OCA\Settings\AppInfo\Application;
use OCP\AppFramework\App;
@@ -22,13 +23,12 @@
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use PHPUnit\Framework\MockObject\MockObject;
-use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class CoordinatorTest extends TestCase {
private AppManager&MockObject $appManager;
- private ContainerInterface&MockObject $serverContainer;
+ private Server&MockObject $serverContainer;
private Registry&MockObject $crashReporterRegistry;
private IManager&MockObject $dashboardManager;
private IEventDispatcher&MockObject $eventDispatcher;
@@ -41,7 +41,7 @@ protected function setUp(): void {
parent::setUp();
$this->appManager = $this->createMock(AppManager::class);
- $this->serverContainer = $this->createMock(ContainerInterface::class);
+ $this->serverContainer = $this->createMock(Server::class);
$this->crashReporterRegistry = $this->createMock(Registry::class);
$this->dashboardManager = $this->createMock(IManager::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
diff --git a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
index 128059d275559..bd82677200460 100644
--- a/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
+++ b/tests/lib/AppFramework/DependencyInjection/DIContainerTest.php
@@ -30,7 +30,7 @@ class DIContainerTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
$this->container = $this->getMockBuilder(DIContainer::class)
- ->onlyMethods(['isAdminUser'])
+ ->onlyMethods([])
->setConstructorArgs(['name'])
->getMock();
}
@@ -138,6 +138,6 @@ public function testMiddlewareDispatcherIncludesGlobalBootstrapMiddlewares(): vo
public function testInvalidAppClass(): void {
$this->expectException(QueryException::class);
- $this->container->query('\OCA\Name\Foo');
+ $this->container->get('\OCA\Name\Foo');
}
}
diff --git a/tests/lib/AppFramework/Utility/SimpleContainerTest.php b/tests/lib/AppFramework/Utility/SimpleContainerTest.php
index 6ad23c9506c81..4bf67d3e52d11 100644
--- a/tests/lib/AppFramework/Utility/SimpleContainerTest.php
+++ b/tests/lib/AppFramework/Utility/SimpleContainerTest.php
@@ -70,7 +70,7 @@ protected function setUp(): void {
public function testRegister(): void {
$this->container->registerParameter('test', 'abc');
- $this->assertEquals('abc', $this->container->query('test'));
+ $this->assertEquals('abc', $this->container->get('test'));
}
/**
@@ -78,7 +78,11 @@ public function testRegister(): void {
*/
public function testNothingRegistered(): void {
try {
- $this->container->query('something really hard', false);
+ $this->invokePrivate(
+ $this->container,
+ 'query',
+ ['something really hard', false]
+ );
$this->fail('Expected `QueryException` exception was not thrown');
} catch (\Throwable $exception) {
$this->assertInstanceOf(QueryException::class, $exception);
@@ -91,7 +95,7 @@ public function testNothingRegistered(): void {
*/
public function testNothingRegistered_autoload(): void {
try {
- $this->container->query('something really hard');
+ $this->container->get('something really hard');
$this->fail('Expected `QueryException` exception was not thrown');
} catch (\Throwable $exception) {
$this->assertInstanceOf(QueryException::class, $exception);
@@ -102,23 +106,23 @@ public function testNothingRegistered_autoload(): void {
public function testNotAClass(): void {
$this->expectException(QueryException::class);
- $this->container->query('Test\AppFramework\Utility\TestInterface');
+ $this->container->get('Test\AppFramework\Utility\TestInterface');
}
public function testNoConstructorClass(): void {
- $object = $this->container->query('Test\AppFramework\Utility\ClassEmptyConstructor');
+ $object = $this->container->get('Test\AppFramework\Utility\ClassEmptyConstructor');
$this->assertTrue($object instanceof ClassEmptyConstructor);
}
public function testInstancesOnlyOnce(): void {
- $object = $this->container->query('Test\AppFramework\Utility\ClassEmptyConstructor');
- $object2 = $this->container->query('Test\AppFramework\Utility\ClassEmptyConstructor');
+ $object = $this->container->get('Test\AppFramework\Utility\ClassEmptyConstructor');
+ $object2 = $this->container->get('Test\AppFramework\Utility\ClassEmptyConstructor');
$this->assertSame($object, $object2);
}
public function testConstructorSimple(): void {
$this->container->registerParameter('test', 'abc');
- $object = $this->container->query(
+ $object = $this->container->get(
'Test\AppFramework\Utility\ClassSimpleConstructor'
);
$this->assertTrue($object instanceof ClassSimpleConstructor);
@@ -127,7 +131,7 @@ public function testConstructorSimple(): void {
public function testConstructorComplex(): void {
$this->container->registerParameter('test', 'abc');
- $object = $this->container->query(
+ $object = $this->container->get(
'Test\AppFramework\Utility\ClassComplexConstructor'
);
$this->assertTrue($object instanceof ClassComplexConstructor);
@@ -139,9 +143,9 @@ public function testConstructorComplexInterface(): void {
$this->container->registerParameter('test', 'abc');
$this->container->registerService(
'Test\AppFramework\Utility\IInterfaceConstructor', function ($c) {
- return $c->query('Test\AppFramework\Utility\ClassSimpleConstructor');
+ return $c->get('Test\AppFramework\Utility\ClassSimpleConstructor');
});
- $object = $this->container->query(
+ $object = $this->container->get(
'Test\AppFramework\Utility\ClassInterfaceConstructor'
);
$this->assertTrue($object instanceof ClassInterfaceConstructor);
@@ -152,13 +156,13 @@ public function testConstructorComplexInterface(): void {
public function testOverrideService(): void {
$this->container->registerService(
'Test\AppFramework\Utility\IInterfaceConstructor', function ($c) {
- return $c->query('Test\AppFramework\Utility\ClassSimpleConstructor');
+ return $c->get('Test\AppFramework\Utility\ClassSimpleConstructor');
});
$this->container->registerService(
'Test\AppFramework\Utility\IInterfaceConstructor', function ($c) {
- return $c->query('Test\AppFramework\Utility\ClassEmptyConstructor');
+ return $c->get('Test\AppFramework\Utility\ClassEmptyConstructor');
});
- $object = $this->container->query(
+ $object = $this->container->get(
'Test\AppFramework\Utility\IInterfaceConstructor'
);
$this->assertTrue($object instanceof ClassEmptyConstructor);
@@ -167,7 +171,7 @@ public function testOverrideService(): void {
public function testRegisterAliasParamter(): void {
$this->container->registerParameter('test', 'abc');
$this->container->registerAlias('test1', 'test');
- $this->assertEquals('abc', $this->container->query('test1'));
+ $this->assertEquals('abc', $this->container->get('test1'));
}
public function testRegisterAliasService(): void {
@@ -176,11 +180,11 @@ public function testRegisterAliasService(): void {
}, true);
$this->container->registerAlias('test1', 'test');
$this->assertSame(
- $this->container->query('test'), $this->container->query('test'));
+ $this->container->get('test'), $this->container->get('test'));
$this->assertSame(
- $this->container->query('test1'), $this->container->query('test1'));
+ $this->container->get('test1'), $this->container->get('test1'));
$this->assertSame(
- $this->container->query('test'), $this->container->query('test1'));
+ $this->container->get('test'), $this->container->get('test1'));
}
public static function sanitizeNameProvider(): array {
@@ -197,13 +201,13 @@ public function testSanitizeName($register, $query): void {
$this->container->registerService($register, function () {
return 'abc';
});
- $this->assertEquals('abc', $this->container->query($query));
+ $this->assertEquals('abc', $this->container->get($query));
}
public function testConstructorComplexNoTestParameterFound(): void {
$this->expectException(QueryException::class);
- $object = $this->container->query(
+ $object = $this->container->get(
'Test\AppFramework\Utility\ClassComplexConstructor'
);
/* Use the object to trigger DI on PHP >= 8.4 */
@@ -215,7 +219,7 @@ public function testRegisterFactory(): void {
return new \StdClass();
}, false);
$this->assertNotSame(
- $this->container->query('test'), $this->container->query('test'));
+ $this->container->get('test'), $this->container->get('test'));
}
public function testRegisterAliasFactory(): void {
@@ -224,17 +228,17 @@ public function testRegisterAliasFactory(): void {
}, false);
$this->container->registerAlias('test1', 'test');
$this->assertNotSame(
- $this->container->query('test'), $this->container->query('test'));
+ $this->container->get('test'), $this->container->get('test'));
$this->assertNotSame(
- $this->container->query('test1'), $this->container->query('test1'));
+ $this->container->get('test1'), $this->container->get('test1'));
$this->assertNotSame(
- $this->container->query('test'), $this->container->query('test1'));
+ $this->container->get('test'), $this->container->get('test1'));
}
public function testQueryUntypedNullable(): void {
$this->expectException(QueryException::class);
- $object = $this->container->query(
+ $object = $this->container->get(
ClassNullableUntypedConstructorArg::class
);
/* Use the object to trigger DI on PHP >= 8.4 */
@@ -243,7 +247,7 @@ public function testQueryUntypedNullable(): void {
public function testQueryTypedNullable(): void {
/** @var ClassNullableTypedConstructorArg $service */
- $service = $this->container->query(ClassNullableTypedConstructorArg::class);
+ $service = $this->container->get(ClassNullableTypedConstructorArg::class);
self::assertNull($service->class);
}
diff --git a/tests/lib/Collaboration/Collaborators/SearchTest.php b/tests/lib/Collaboration/Collaborators/SearchTest.php
index 8bb9611c66007..c8e91949356bf 100644
--- a/tests/lib/Collaboration/Collaborators/SearchTest.php
+++ b/tests/lib/Collaboration/Collaborators/SearchTest.php
@@ -1,5 +1,7 @@
createMock(ISearchPlugin::class);
$userPlugin->expects($this->any())
->method('search')
- ->willReturnCallback(function () use ($searchResult, $mockedUserResult, $expectedMoreResults) {
+ ->willReturnCallback(function (string $search, int $limit, int $offset, ISearchResult $searchResult) use ($mockedUserResult, $expectedMoreResults) {
$type = new SearchResultType('users');
$searchResult->addResultSet($type, $mockedUserResult);
return $expectedMoreResults;
@@ -62,7 +62,7 @@ public function testSearch(
$groupPlugin = $this->createMock(ISearchPlugin::class);
$groupPlugin->expects($this->any())
->method('search')
- ->willReturnCallback(function () use ($searchResult, $mockedGroupsResult, $expectedMoreResults) {
+ ->willReturnCallback(function (string $search, int $limit, int $offset, ISearchResult $searchResult) use ($mockedGroupsResult, $expectedMoreResults) {
$type = new SearchResultType('groups');
$searchResult->addResultSet($type, $mockedGroupsResult);
return $expectedMoreResults;
@@ -71,7 +71,7 @@ public function testSearch(
$remotePlugin = $this->createMock(ISearchPlugin::class);
$remotePlugin->expects($this->any())
->method('search')
- ->willReturnCallback(function () use ($searchResult, $mockedRemotesResult, $expectedMoreResults) {
+ ->willReturnCallback(function (string $search, int $limit, int $offset, ISearchResult $searchResult) use ($mockedRemotesResult, $expectedMoreResults) {
if ($mockedRemotesResult !== null) {
$type = new SearchResultType('remotes');
$searchResult->addResultSet($type, $mockedRemotesResult['results'], $mockedRemotesResult['exact']);
@@ -85,21 +85,12 @@ public function testSearch(
$mailPlugin = $this->createMock(ISearchPlugin::class);
$mailPlugin->expects($this->any())
->method('search')
- ->willReturnCallback(function () use ($searchResult, $mockedMailResult, $expectedMoreResults) {
+ ->willReturnCallback(function (string $search, int $limit, int $offset, ISearchResult $searchResult) use ($mockedMailResult, $expectedMoreResults) {
$type = new SearchResultType('emails');
$searchResult->addResultSet($type, $mockedMailResult);
return $expectedMoreResults;
});
- $this->container->expects($this->any())
- ->method('resolve')
- ->willReturnCallback(function ($class) use ($searchResult) {
- if ($class === SearchResult::class) {
- return $searchResult;
- }
- return null;
- });
-
$this->container->expects($this->any())
->method('get')
->willReturnCallback(function ($class) use ($userPlugin, $groupPlugin, $remotePlugin, $mailPlugin) {
diff --git a/tests/lib/Command/AsyncBusTestCase.php b/tests/lib/Command/AsyncBusTestCase.php
index 7682a27abea8c..491343b14a6cf 100644
--- a/tests/lib/Command/AsyncBusTestCase.php
+++ b/tests/lib/Command/AsyncBusTestCase.php
@@ -8,7 +8,6 @@
namespace Test\Command;
-use OC\Command\FileAccess;
use OCP\Command\IBus;
use OCP\Command\ICommand;
use Test\TestCase;
@@ -32,8 +31,11 @@ public function handle() {
}
}
+trait SyncCommand {
+};
+
class FilesystemCommand implements ICommand {
- use FileAccess;
+ use SyncCommand;
#[\Override]
public function handle() {
@@ -102,7 +104,7 @@ public function testFileFileAccessCommand(): void {
}
public function testFileFileAccessCommandSync(): void {
- $this->getBus()->requireSync('\OC\Command\FileAccess');
+ $this->getBus()->requireSync(SyncCommand::class);
$this->getBus()->push(new FilesystemCommand());
$this->assertEquals('FileAccess', self::$lastCommand);
self::$lastCommand = '';
diff --git a/tests/lib/Files/SimpleFS/SimpleFolderTest.php b/tests/lib/Files/SimpleFS/SimpleFolderTest.php
index 5583fa1f59688..1616d09f5a1e5 100644
--- a/tests/lib/Files/SimpleFS/SimpleFolderTest.php
+++ b/tests/lib/Files/SimpleFS/SimpleFolderTest.php
@@ -10,9 +10,11 @@
use OC\Files\SimpleFS\SimpleFolder;
use OC\Files\Storage\Temporary;
use OCP\Files\Folder;
+use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Files\SimpleFS\ISimpleFolder;
+use OCP\Server;
use Test\Traits\MountProviderTrait;
use Test\Traits\UserTrait;
@@ -41,7 +43,7 @@ protected function setUp(): void {
$this->registerMount('simple', $this->storage, '/simple/files');
$this->loginAsUser('simple');
- $this->parentFolder = \OC::$server->getUserFolder('simple');
+ $this->parentFolder = Server::get(IRootFolder::class)->getUserFolder('simple');
$this->folder = $this->parentFolder->newFolder('test');
$this->simpleFolder = new SimpleFolder($this->folder);
diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php
index 3b8718564020e..8a8ea6d64d566 100644
--- a/tests/lib/Files/ViewTest.php
+++ b/tests/lib/Files/ViewTest.php
@@ -28,6 +28,7 @@
use OCP\Files\ForbiddenException;
use OCP\Files\GenericFileException;
use OCP\Files\InvalidPathException;
+use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorage;
@@ -1719,7 +1720,7 @@ public function testMoveMountPointIntoSharedFolder(): void {
$fileId = $view->getFileInfo('shareddir')->getId();
$userObject = Server::get(IUserManager::class)->createUser('test2', 'IHateNonMockableStaticClasses');
- $userFolder = \OC::$server->getUserFolder(self::$user);
+ $userFolder = Server::get(IRootFolder::class)->getUserFolder(self::$user);
$shareDir = $userFolder->get('shareddir');
$shareManager = Server::get(IShareManager::class);
$share = $shareManager->newShare();
diff --git a/tests/lib/ServerTest.php b/tests/lib/ServerTest.php
index a715890d3c149..052c41bd31a93 100644
--- a/tests/lib/ServerTest.php
+++ b/tests/lib/ServerTest.php
@@ -51,7 +51,7 @@ public static function dataTestQuery(): array {
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dataTestQuery')]
public function testQuery(string $serviceName, string $instanceOf): void {
- $this->assertInstanceOf($instanceOf, $this->server->query($serviceName), 'Service "' . $serviceName . '"" did not return the right class');
+ $this->assertInstanceOf($instanceOf, $this->server->get($serviceName), 'Service "' . $serviceName . '"" did not return the right class');
}
public function testOverwriteDefaultCommentsManager(): void {
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php
index 2f5b34fea6228..29815ca2eafb4 100644
--- a/tests/lib/TestCase.php
+++ b/tests/lib/TestCase.php
@@ -57,6 +57,7 @@ protected function onNotSuccessfulTest(\Throwable $t): never {
// restore database connection
if (!$this->IsDatabaseAccessAllowed()) {
+ /** @psalm-suppress InternalMethod */
\OC::$server->registerService(IDBConnection::class, function () {
return self::$realDatabase;
});
@@ -79,6 +80,7 @@ public function overwriteService(string $name, mixed $newService): bool {
$container = \OC::$server->getAppContainerForService($name);
$container = $container ?? \OC::$server;
+ /** @psalm-suppress InternalMethod */
$container->registerService($name, function () use ($newService) {
return $newService;
});
@@ -95,6 +97,7 @@ public function restoreService(string $name): bool {
$container = $container ?? \OC::$server;
if ($oldService !== false) {
+ /** @psalm-suppress InternalMethod */
$container->registerService($name, function () use ($oldService) {
return $oldService;
});
@@ -340,6 +343,7 @@ public static function tearDownAfterClass(): void {
if (!self::$wasDatabaseAllowed && self::$realDatabase !== null) {
// in case an error is thrown in a test, PHPUnit jumps straight to tearDownAfterClass,
// so we need the database again
+ /** @psalm-suppress InternalMethod */
\OC::$server->registerService(IDBConnection::class, function () {
return self::$realDatabase;
});
diff --git a/tests/lib/Traits/EncryptionTrait.php b/tests/lib/Traits/EncryptionTrait.php
index 7b3c016d52276..0ce4395a363bf 100644
--- a/tests/lib/Traits/EncryptionTrait.php
+++ b/tests/lib/Traits/EncryptionTrait.php
@@ -17,6 +17,7 @@
use OCA\Encryption\Users\Setup;
use OCP\App\IAppManager;
use OCP\Encryption\IManager;
+use OCP\Files\IRootFolder;
use OCP\Files\ISetupManager;
use OCP\IAppConfig;
use OCP\IConfig;
@@ -67,7 +68,7 @@ protected function loginWithEncryption($user = '') {
$this->postLogin();
\OC_Util::setupFS($user);
if ($this->userManagerEncTrait->userExists($user)) {
- \OC::$server->getUserFolder($user);
+ Server::get(IRootFolder::class)->getUserFolder($user);
}
}
@@ -76,12 +77,10 @@ protected function setupForUser($name, $password) {
$this->setupManagerEncTrait->setupForUser($this->userManagerEncTrait->get($name));
$container = $this->encryptionApp->getContainer();
- /** @var KeyManager $keyManager */
- $keyManager = $container->query(KeyManager::class);
- /** @var Setup $userSetup */
- $userSetup = $container->query(Setup::class);
+ $keyManager = $container->get(KeyManager::class);
+ $userSetup = $container->get(Setup::class);
$userSetup->setupUser($name, $password);
- $encryptionManager = $container->query(IManager::class);
+ $encryptionManager = $container->get(IManager::class);
$this->encryptionApp->setUp($encryptionManager);
$keyManager->init($name, $password);
$this->invokePrivate($keyManager, 'keyUid', [$name]);