Skip to content

Commit 7c8c035

Browse files
Merge pull request #60780 from nextcloud/carl/modernize-containers
refactor: Remove most usages of IAppContainer and IServerContainer
2 parents e92c919 + 326e3d6 commit 7c8c035

31 files changed

Lines changed: 118 additions & 188 deletions

File tree

apps/dav/lib/CalDAV/CalendarHome.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCP\App\IAppManager;
1717
use OCP\IConfig;
1818
use OCP\IL10N;
19+
use OCP\L10N\IFactory;
1920
use OCP\Server;
2021
use Psr\Log\LoggerInterface;
2122
use Sabre\CalDAV\Backend\BackendInterface;
@@ -50,7 +51,7 @@ public function __construct(
5051
private bool $returnCachedSubscriptions,
5152
) {
5253
parent::__construct($caldavBackend, $principalInfo);
53-
$this->l10n = \OC::$server->getL10N('dav');
54+
$this->l10n = Server::get(IFactory::class)->get('dav');
5455
$this->config = Server::get(IConfig::class);
5556
$this->pluginManager = new PluginManager(
5657
\OC::$server,

apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\EventDispatcher\IEventDispatcher;
2727
use OCP\IConfig;
2828
use OCP\IURLGenerator;
29+
use OCP\L10N\IFactory;
2930
use OCP\Server;
3031
use Psr\Log\LoggerInterface;
3132
use Sabre\VObject\ITip\Message;
@@ -46,7 +47,7 @@ public function __construct(bool $public = true) {
4647
$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
4748

4849
// Add maintenance plugin
49-
$this->server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), \OC::$server->getL10N('dav')));
50+
$this->server->addPlugin(new MaintenancePlugin(Server::get(IConfig::class), Server::get(IFactory::class)->get('dav')));
5051

5152
// Set URL explicitly due to reverse-proxy situations
5253
$this->server->httpRequest->setUrl($baseUri);

apps/dav/lib/Connector/Sabre/MaintenancePlugin.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
class MaintenancePlugin extends ServerPlugin {
1919

20-
/** @var IL10N */
21-
private $l10n;
22-
2320
/**
2421
* Reference to main server object
2522
*
@@ -31,10 +28,9 @@ class MaintenancePlugin extends ServerPlugin {
3128
* @param IConfig $config
3229
*/
3330
public function __construct(
34-
private IConfig $config,
35-
IL10N $l10n,
31+
private readonly IConfig $config,
32+
private readonly IL10N $l10n,
3633
) {
37-
$this->l10n = \OC::$server->getL10N('dav');
3834
}
3935

4036
/**
@@ -59,9 +55,8 @@ public function initialize(\Sabre\DAV\Server $server) {
5955
* in case the system is in maintenance mode.
6056
*
6157
* @throws ServiceUnavailable
62-
* @return bool
6358
*/
64-
public function checkMaintenanceMode() {
59+
public function checkMaintenanceMode(): bool {
6560
if ($this->config->getSystemValueBool('maintenance')) {
6661
throw new ServerMaintenanceMode($this->l10n->t('System is in maintenance mode.'));
6762
}

apps/dav/lib/RootCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
class RootCollection extends SimpleCollection {
5555
public function __construct() {
56-
$l10n = \OC::$server->getL10N('dav');
56+
$l10n = Server::get(IFactory::class)->get('dav');
5757
$random = Server::get(ISecureRandom::class);
5858
$logger = Server::get(LoggerInterface::class);
5959
$userManager = Server::get(IUserManager::class);

apps/dav/lib/Server.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
use OCP\ITagManager;
9797
use OCP\IURLGenerator;
9898
use OCP\IUserSession;
99+
use OCP\L10N\IFactory;
99100
use OCP\Mail\IEmailValidator;
100101
use OCP\Mail\IMailer;
101102
use OCP\Profiler\IProfiler;
@@ -133,7 +134,7 @@ public function __construct(
133134
$this->server->setLogger($logger);
134135

135136
// Add maintenance plugin
136-
$this->server->addPlugin(new MaintenancePlugin(\OCP\Server::get(IConfig::class), \OC::$server->getL10N('dav')));
137+
$this->server->addPlugin(new MaintenancePlugin(\OCP\Server::get(IConfig::class), \OCP\Server::get(IFactory::class)->get('dav')));
137138

138139
$this->server->addPlugin(new AppleQuirksPlugin());
139140

@@ -401,7 +402,7 @@ public function __construct(
401402
\OCP\Server::get(IURLGenerator::class),
402403
\OCP\Server::get(ThemingDefaults::class),
403404
\OCP\Server::get(IRequest::class),
404-
\OC::$server->getL10N('dav'),
405+
\OCP\Server::get(IFactory::class)->get('dav'),
405406
function () {
406407
return UUIDUtil::getUUID();
407408
}

apps/files_external/tests/Service/StoragesServiceTestCase.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use OCA\Files_External\Service\BackendService;
2323
use OCA\Files_External\Service\DBConfigService;
2424
use OCA\Files_External\Service\StoragesService;
25-
use OCP\AppFramework\IAppContainer;
2625
use OCP\EventDispatcher\IEventDispatcher;
2726
use OCP\Files\Cache\ICache;
2827
use OCP\Files\Config\IUserMountCache;
@@ -128,14 +127,6 @@ protected function setUp(): void {
128127
Filesystem::CLASSNAME,
129128
Filesystem::signal_delete_mount,
130129
get_class($this), 'deleteHookCallback');
131-
132-
$containerMock = $this->createMock(IAppContainer::class);
133-
$containerMock->method('query')
134-
->willReturnCallback(function ($name) {
135-
if ($name === 'OCA\Files_External\Service\BackendService') {
136-
return $this->backendService;
137-
}
138-
});
139130
}
140131

141132
protected function tearDown(): void {

apps/files_sharing/lib/AppInfo/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ public function registerEventsScripts(IEventDispatcher $dispatcher): void {
165165
// notifications api to accept incoming user shares
166166
$dispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event): void {
167167
/** @var Listener $listener */
168-
$listener = $this->getContainer()->query(Listener::class);
168+
$listener = $this->getContainer()->get(Listener::class);
169169
$listener->shareNotification($event);
170170
});
171171
$dispatcher->addListener(IGroup::class . '::postAddUser', function ($event): void {
172172
if (!$event instanceof OldGenericEvent) {
173173
return;
174174
}
175175
/** @var Listener $listener */
176-
$listener = $this->getContainer()->query(Listener::class);
176+
$listener = $this->getContainer()->get(Listener::class);
177177
$listener->userAddedToGroup($event);
178178
});
179179
}

apps/settings/tests/AppInfo/ApplicationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
use OCA\Settings\Controller\UsersController;
1818
use OCA\Settings\Middleware\SubadminMiddleware;
1919
use OCP\AppFramework\Controller;
20-
use OCP\AppFramework\IAppContainer;
2120
use OCP\AppFramework\Middleware;
21+
use Psr\Container\ContainerInterface;
2222
use Test\TestCase;
2323

2424
/**
@@ -29,7 +29,7 @@
2929
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
3030
class ApplicationTest extends TestCase {
3131
protected Application $app;
32-
protected IAppContainer $container;
32+
protected ContainerInterface $container;
3333

3434
protected function setUp(): void {
3535
parent::setUp();

apps/theming/tests/ServicesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
use OCA\Theming\ThemingDefaults;
1616
use OCA\Theming\Util;
1717
use OCP\AppFramework\App;
18-
use OCP\AppFramework\IAppContainer;
1918
use OCP\Capabilities\ICapability;
2019
use OCP\IL10N;
2120
use OCP\Settings\IIconSection;
2221
use OCP\Settings\ISettings;
22+
use Psr\Container\ContainerInterface;
2323
use Test\TestCase;
2424

2525
/**
@@ -31,7 +31,7 @@
3131
class ServicesTest extends TestCase {
3232
protected App $app;
3333

34-
protected IAppContainer $container;
34+
protected ContainerInterface $container;
3535

3636
protected function setUp(): void {
3737
parent::setUp();
@@ -66,6 +66,6 @@ public function testContainerQuery(string $service, ?string $expected = null): v
6666
if ($expected === null) {
6767
$expected = $service;
6868
}
69-
$this->assertInstanceOf($expected, $this->container->query($service));
69+
$this->assertInstanceOf($expected, $this->container->get($service));
7070
}
7171
}

apps/user_ldap/lib/AppInfo/Application.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use OCP\AppFramework\Bootstrap\IBootContext;
3131
use OCP\AppFramework\Bootstrap\IBootstrap;
3232
use OCP\AppFramework\Bootstrap\IRegistrationContext;
33-
use OCP\AppFramework\IAppContainer;
3433
use OCP\AppFramework\Services\IAppConfig;
3534
use OCP\Config\IUserConfig;
3635
use OCP\EventDispatcher\IEventDispatcher;
@@ -86,7 +85,7 @@ function (ContainerInterface $c) {
8685
public function boot(IBootContext $context): void {
8786
$context->injectFn(function (
8887
INotificationManager $notificationManager,
89-
IAppContainer $appContainer,
88+
ContainerInterface $appContainer,
9089
IEventDispatcher $dispatcher,
9190
IUserManager $userManager,
9291
IGroupManager $groupManager,
@@ -120,7 +119,7 @@ public function boot(IBootContext $context): void {
120119
);
121120
}
122121

123-
private function registerBackendDependents(IAppContainer $appContainer, IEventDispatcher $dispatcher): void {
122+
private function registerBackendDependents(ContainerInterface $appContainer, IEventDispatcher $dispatcher): void {
124123
$dispatcher->addListener(
125124
'OCA\\Files_External::loadAdditionalBackends',
126125
function () use ($appContainer): void {

0 commit comments

Comments
 (0)