Skip to content

Commit ca449ff

Browse files
committed
refactor: Remove most usages of IAppContainer and IServerContainer
Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent a118773 commit ca449ff

15 files changed

Lines changed: 57 additions & 78 deletions

File tree

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/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/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
}

apps/user_ldap/lib/AppInfo/Application.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use OCP\AppFramework\Bootstrap\IBootContext;
3030
use OCP\AppFramework\Bootstrap\IBootstrap;
3131
use OCP\AppFramework\Bootstrap\IRegistrationContext;
32-
use OCP\AppFramework\IAppContainer;
3332
use OCP\AppFramework\Services\IAppConfig;
3433
use OCP\Config\IUserConfig;
3534
use OCP\EventDispatcher\IEventDispatcher;
@@ -85,7 +84,7 @@ function (ContainerInterface $c) {
8584
public function boot(IBootContext $context): void {
8685
$context->injectFn(function (
8786
INotificationManager $notificationManager,
88-
IAppContainer $appContainer,
87+
ContainerInterface $appContainer,
8988
IEventDispatcher $dispatcher,
9089
IUserManager $userManager,
9190
IGroupManager $groupManager,
@@ -119,7 +118,7 @@ public function boot(IBootContext $context): void {
119118
);
120119
}
121120

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

lib/private/AppFramework/Bootstrap/BootContext.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@
99
namespace OC\AppFramework\Bootstrap;
1010

1111
use OCP\AppFramework\Bootstrap\IBootContext;
12-
use OCP\AppFramework\IAppContainer;
1312
use OCP\IServerContainer;
1413

1514
class BootContext implements IBootContext {
1615
public function __construct(
17-
private IAppContainer $appContainer,
16+
private ContainerInterface $appContainer,
1817
) {
1918
}
2019

2120
#[\Override]
22-
public function getAppContainer(): IAppContainer {
21+
public function getAppContainer(): ContainerInterface {
2322
return $this->appContainer;
2423
}
2524

2625
#[\Override]
27-
public function getServerContainer(): IServerContainer {
26+
public function getServerContainer(): ContainerInterface {
2827
return $this->appContainer->get(IServerContainer::class);
2928
}
3029

lib/private/AppFramework/Bootstrap/FunctionInjector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace OC\AppFramework\Bootstrap;
1010

1111
use Closure;
12-
use OCP\AppFramework\QueryException;
12+
use Psr\Container\ContainerExceptionInterface;
1313
use Psr\Container\ContainerInterface;
1414
use ReflectionFunction;
1515
use ReflectionParameter;
@@ -28,14 +28,14 @@ public function injectFn(callable $fn) {
2828
if (($type = $param->getType()) !== null) {
2929
try {
3030
return $this->container->get($type->getName());
31-
} catch (QueryException $ex) {
31+
} catch (ContainerExceptionInterface) {
3232
// Ignore and try name as well
3333
}
3434
}
3535
// Second we try by name (mostly for primitives)
3636
try {
3737
return $this->container->get($param->getName());
38-
} catch (QueryException $ex) {
38+
} catch (ContainerExceptionInterface $ex) {
3939
// As a last resort we pass `null` if allowed
4040
if ($type !== null && $type->allowsNull()) {
4141
return null;

lib/private/Log/LogFactory.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,29 @@
88

99
use OC\Log;
1010
use OC\SystemConfig;
11-
use OCP\AppFramework\QueryException;
12-
use OCP\IServerContainer;
1311
use OCP\Log\ILogFactory;
1412
use OCP\Log\IWriter;
13+
use Psr\Container\ContainerExceptionInterface;
14+
use Psr\Container\ContainerInterface;
1515
use Psr\Log\LoggerInterface;
1616

1717
class LogFactory implements ILogFactory {
1818
public function __construct(
19-
private IServerContainer $c,
20-
private SystemConfig $systemConfig,
19+
private readonly ContainerInterface $c,
20+
private readonly SystemConfig $systemConfig,
21+
private readonly string $serverRoot,
2122
) {
2223
}
2324

2425
/**
25-
* @throws QueryException
26+
* @throws ContainerExceptionInterface
2627
*/
2728
#[\Override]
2829
public function get(string $type):IWriter {
2930
return match (strtolower($type)) {
3031
'errorlog' => new Errorlog($this->systemConfig),
31-
'syslog' => $this->c->resolve(Syslog::class),
32-
'systemd' => $this->c->resolve(Systemdlog::class),
32+
'syslog' => $this->c->get(Syslog::class),
33+
'systemd' => $this->c->get(Systemdlog::class),
3334
'file' => $this->buildLogFile(),
3435
default => $this->buildLogFile(),
3536
};
@@ -53,7 +54,7 @@ public function getCustomPsrLogger(string $path, string $type = 'file', string $
5354
}
5455

5556
protected function buildLogFile(string $logFile = ''): File {
56-
$defaultLogFile = $this->systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log';
57+
$defaultLogFile = $this->systemConfig->getValue('datadirectory', $this->serverRoot . '/data') . '/nextcloud.log';
5758
if ($logFile === '') {
5859
$logFile = $this->systemConfig->getValue('logfile', $defaultLogFile);
5960
}

lib/private/User/Session.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,10 @@ public function logout() {
959959
$user = $this->getUser();
960960
$this->manager->emit('\OC\User', 'logout', [$user]);
961961
if ($user !== null) {
962+
$this->logger->error('User logged out', [
963+
'exception' => new \RuntimeException('Logout'),
964+
'app' => 'core',
965+
]);
962966
try {
963967
$token = $this->session->getId();
964968
$this->tokenProvider->invalidateToken($token);

lib/public/AppFramework/App.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCP\IConfig;
1515
use OCP\Server;
1616
use Psr\Container\ContainerExceptionInterface;
17+
use Psr\Container\ContainerInterface;
1718
use Psr\Log\LoggerInterface;
1819

1920
/**
@@ -97,10 +98,11 @@ public function __construct(string $appName, array $urlParams = []) {
9798
}
9899

99100
/**
100-
* @return IAppContainer
101+
* @return ContainerInterface
101102
* @since 6.0.0
103+
* @since 35.0.0 Typed as returning a ContainerInterface instead of the deprecated IAppContainer
102104
*/
103-
public function getContainer(): IAppContainer {
105+
public function getContainer(): ContainerInterface {
104106
return $this->container;
105107
}
106108

lib/public/AppFramework/Bootstrap/IBootContext.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,35 @@
88
*/
99
namespace OCP\AppFramework\Bootstrap;
1010

11-
use OCP\AppFramework\IAppContainer;
12-
use OCP\IServerContainer;
11+
use OCP\AppFramework\Attribute\Consumable;
1312
use Psr\Container\ContainerExceptionInterface;
13+
use Psr\Container\ContainerInterface;
1414
use Throwable;
1515

1616
/**
1717
* @since 20.0.0
1818
*/
19+
#[Consumable(since: '20.0.0')]
1920
interface IBootContext {
2021
/**
2122
* Get hold of the app's container
2223
*
2324
* Useful to register and query app-specific services
2425
*
25-
* @return IAppContainer
2626
* @since 20.0.0
27+
* @since 35.0.0 Typed as returning a ContainerInterface instead of the deprecated IAppContainer
2728
*/
28-
public function getAppContainer(): IAppContainer;
29+
public function getAppContainer(): ContainerInterface;
2930

3031
/**
3132
* Get hold of the server DI container
3233
*
3334
* Useful to register and query system-wide services
3435
*
35-
* @return IServerContainer
3636
* @since 20.0.0
37+
* @since 35.0.0 Typed as returning a ContainerInterface instead of the deprecated IServerContainer
3738
*/
38-
public function getServerContainer(): IServerContainer;
39+
public function getServerContainer(): ContainerInterface;
3940

4041
/**
4142
* Invoke the given callable and inject all parameters based on their types

0 commit comments

Comments
 (0)