Skip to content

Commit 7d2081f

Browse files
committed
refactor: Remove most usages of IAppContainer and IServerContainer
And port more stuff to standard ContainerInterface interface Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent a118773 commit 7d2081f

30 files changed

Lines changed: 119 additions & 162 deletions

File tree

apps/dav/lib/CalDAV/CalendarHome.php

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

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

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

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

5051
// Set URL explicitly due to reverse-proxy situations
5152
$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
@@ -16,9 +16,6 @@
1616

1717
class MaintenancePlugin extends ServerPlugin {
1818

19-
/** @var IL10N */
20-
private $l10n;
21-
2219
/**
2320
* Reference to main server object
2421
*
@@ -30,10 +27,9 @@ class MaintenancePlugin extends ServerPlugin {
3027
* @param IConfig $config
3128
*/
3229
public function __construct(
33-
private IConfig $config,
34-
IL10N $l10n,
30+
private readonly IConfig $config,
31+
private readonly IL10N $l10n,
3532
) {
36-
$this->l10n = \OC::$server->getL10N('dav');
3733
}
3834

3935

@@ -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
@@ -52,7 +52,7 @@
5252

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

apps/dav/lib/Server.php

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

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

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

@@ -398,7 +399,7 @@ public function __construct(
398399
\OCP\Server::get(IURLGenerator::class),
399400
\OCP\Server::get(ThemingDefaults::class),
400401
\OCP\Server::get(IRequest::class),
401-
\OC::$server->getL10N('dav'),
402+
\OCP\Server::get(IFactory::class)->get('dav'),
402403
function () {
403404
return UUIDUtil::getUUID();
404405
}

apps/files_external/tests/Service/StoragesServiceTestCase.php

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

140131
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
@@ -161,15 +161,15 @@ public function registerEventsScripts(IEventDispatcher $dispatcher): void {
161161
// notifications api to accept incoming user shares
162162
$dispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event): void {
163163
/** @var Listener $listener */
164-
$listener = $this->getContainer()->query(Listener::class);
164+
$listener = $this->getContainer()->get(Listener::class);
165165
$listener->shareNotification($event);
166166
});
167167
$dispatcher->addListener(IGroup::class . '::postAddUser', function ($event): void {
168168
if (!$event instanceof OldGenericEvent) {
169169
return;
170170
}
171171
/** @var Listener $listener */
172-
$listener = $this->getContainer()->query(Listener::class);
172+
$listener = $this->getContainer()->get(Listener::class);
173173
$listener->userAddedToGroup($event);
174174
});
175175
}

apps/settings/tests/AppInfo/ApplicationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
use OCA\Settings\Controller\UsersController;
1717
use OCA\Settings\Middleware\SubadminMiddleware;
1818
use OCP\AppFramework\Controller;
19-
use OCP\AppFramework\IAppContainer;
2019
use OCP\AppFramework\Middleware;
20+
use Psr\Container\ContainerInterface;
2121
use Test\TestCase;
2222

2323
/**
@@ -28,7 +28,7 @@
2828
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
2929
class ApplicationTest extends TestCase {
3030
protected Application $app;
31-
protected IAppContainer $container;
31+
protected ContainerInterface $container;
3232

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

apps/systemtags/lib/AppInfo/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function boot(IBootContext $context): void {
4646
$context->injectFn(function (IEventDispatcher $dispatcher) use ($context): void {
4747
$managerListener = function (ManagerEvent $event) use ($context): void {
4848
/** @var Listener $listener */
49-
$listener = $context->getServerContainer()->query(Listener::class);
49+
$listener = $context->getServerContainer()->get(Listener::class);
5050
$listener->event($event);
5151
};
5252
$dispatcher->addListener(ManagerEvent::EVENT_CREATE, $managerListener);
@@ -55,7 +55,7 @@ public function boot(IBootContext $context): void {
5555

5656
$mapperListener = function (MapperEvent $event) use ($context): void {
5757
/** @var Listener $listener */
58-
$listener = $context->getServerContainer()->query(Listener::class);
58+
$listener = $context->getServerContainer()->get(Listener::class);
5959
$listener->mapperEvent($event);
6060
};
6161
$dispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener);

apps/theming/tests/ServicesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
use OCA\Theming\ThemingDefaults;
1515
use OCA\Theming\Util;
1616
use OCP\AppFramework\App;
17-
use OCP\AppFramework\IAppContainer;
1817
use OCP\Capabilities\ICapability;
1918
use OCP\IL10N;
2019
use OCP\Settings\IIconSection;
2120
use OCP\Settings\ISettings;
21+
use Psr\Container\ContainerInterface;
2222
use Test\TestCase;
2323

2424
/**
@@ -30,7 +30,7 @@
3030
class ServicesTest extends TestCase {
3131
protected App $app;
3232

33-
protected IAppContainer $container;
33+
protected ContainerInterface $container;
3434

3535
protected function setUp(): void {
3636
parent::setUp();
@@ -65,6 +65,6 @@ public function testContainerQuery(string $service, ?string $expected = null): v
6565
if ($expected === null) {
6666
$expected = $service;
6767
}
68-
$this->assertInstanceOf($expected, $this->container->query($service));
68+
$this->assertInstanceOf($expected, $this->container->get($service));
6969
}
7070
}

0 commit comments

Comments
 (0)