Skip to content

Commit cc0e585

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 62dd632 commit cc0e585

31 files changed

Lines changed: 125 additions & 197 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

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

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
@@ -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
@@ -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/systemtags/lib/AppInfo/Application.php

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

5757
$mapperListener = function (MapperEvent $event) use ($context): void {
5858
/** @var Listener $listener */
59-
$listener = $context->getServerContainer()->query(Listener::class);
59+
$listener = $context->getServerContainer()->get(Listener::class);
6060
$listener->mapperEvent($event);
6161
};
6262
$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
@@ -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
}

0 commit comments

Comments
 (0)