Skip to content

Commit 9680004

Browse files
committed
chore: Remove almost all uses of deprecated IServerContainer in lib/private
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 3e4a141 commit 9680004

31 files changed

Lines changed: 130 additions & 187 deletions

File tree

lib/private/AppFramework/Bootstrap/Coordinator.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use OCP\Dashboard\IManager;
2020
use OCP\Diagnostics\IEventLogger;
2121
use OCP\EventDispatcher\IEventDispatcher;
22-
use OCP\IServerContainer;
2322
use Psr\Container\ContainerExceptionInterface;
23+
use Psr\Container\ContainerInterface;
2424
use Psr\Log\LoggerInterface;
2525
use Throwable;
2626
use function class_exists;
@@ -35,7 +35,7 @@ class Coordinator {
3535
private array $bootedApps = [];
3636

3737
public function __construct(
38-
private IServerContainer $serverContainer,
38+
private ContainerInterface $serverContainer,
3939
private Registry $registry,
4040
private IManager $dashboardManager,
4141
private IEventDispatcher $eventDispatcher,
@@ -99,7 +99,7 @@ private function registerApps(array $appIds): void {
9999
$this->eventLogger->start("bootstrap:register_app:$appId:application", "Load `Application` instance for $appId");
100100
try {
101101
/** @var IBootstrap&App $application */
102-
$application = $this->serverContainer->query($applicationClassName);
102+
$application = $this->serverContainer->get($applicationClassName);
103103
$apps[$appId] = $application;
104104
} catch (ContainerExceptionInterface $e) {
105105
// Weird, but ok
@@ -162,10 +162,8 @@ public function bootApp(string $appId): void {
162162
*/
163163
$this->eventLogger->start('bootstrap:boot_app:' . $appId, "Call `Application::boot` for $appId");
164164
try {
165-
/** @var App $application */
166-
$application = $this->serverContainer->query($applicationClassName);
167-
if ($application instanceof IBootstrap) {
168-
/** @var BootContext $context */
165+
$application = $this->serverContainer->get($applicationClassName);
166+
if ($application instanceof IBootstrap && $application instanceof App) {
169167
$context = new BootContext($application->getContainer());
170168
$application->boot($context);
171169
}

lib/private/Calendar/Resource/Manager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use OCP\AppFramework\QueryException;
1414
use OCP\Calendar\Resource\IBackend;
1515
use OCP\Calendar\Resource\IManager;
16-
use OCP\IServerContainer;
16+
use Psr\Container\ContainerInterface;
1717

1818
class Manager implements IManager {
1919
private bool $bootstrapBackendsLoaded = false;
@@ -29,7 +29,7 @@ class Manager implements IManager {
2929

3030
public function __construct(
3131
private Coordinator $bootstrapCoordinator,
32-
private IServerContainer $server,
32+
private ContainerInterface $container,
3333
private ResourcesRoomsUpdater $updater,
3434
) {
3535
}
@@ -84,7 +84,7 @@ public function getBackends():array {
8484
continue;
8585
}
8686

87-
$this->initializedBackends[$backend] = $this->server->query($backend);
87+
$this->initializedBackends[$backend] = $this->container->get($backend);
8888
}
8989

9090
return array_values($this->initializedBackends);

lib/private/Calendar/Room/Manager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use OCP\AppFramework\QueryException;
1414
use OCP\Calendar\Room\IBackend;
1515
use OCP\Calendar\Room\IManager;
16-
use OCP\IServerContainer;
16+
use Psr\Container\ContainerInterface;
1717

1818
class Manager implements IManager {
1919
private bool $bootstrapBackendsLoaded = false;
@@ -29,7 +29,7 @@ class Manager implements IManager {
2929

3030
public function __construct(
3131
private Coordinator $bootstrapCoordinator,
32-
private IServerContainer $server,
32+
private ContainerInterface $container,
3333
private ResourcesRoomsUpdater $updater,
3434
) {
3535
}
@@ -91,7 +91,7 @@ public function getBackends():array {
9191
* The backend might have services injected that can't be build from the
9292
* server container.
9393
*/
94-
$this->initializedBackends[$backend] = $this->server->query($backend);
94+
$this->initializedBackends[$backend] = $this->container->get($backend);
9595
}
9696

9797
return array_values($this->initializedBackends);

lib/private/Collaboration/Resources/ProviderManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use OCP\AppFramework\QueryException;
1212
use OCP\Collaboration\Resources\IProvider;
1313
use OCP\Collaboration\Resources\IProviderManager;
14-
use OCP\IServerContainer;
14+
use Psr\Container\ContainerInterface;
1515
use Psr\Log\LoggerInterface;
1616

1717
class ProviderManager implements IProviderManager {
@@ -22,7 +22,7 @@ class ProviderManager implements IProviderManager {
2222
protected array $providerInstances = [];
2323

2424
public function __construct(
25-
protected IServerContainer $serverContainer,
25+
protected ContainerInterface $serverContainer,
2626
protected LoggerInterface $logger,
2727
) {
2828
}
@@ -32,7 +32,7 @@ public function getResourceProviders(): array {
3232
if ($this->providers !== []) {
3333
foreach ($this->providers as $provider) {
3434
try {
35-
$this->providerInstances[] = $this->serverContainer->query($provider);
35+
$this->providerInstances[] = $this->serverContainer->get($provider);
3636
} catch (QueryException $e) {
3737
$this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [
3838
'exception' => $e,

lib/private/Comments/ManagerFactory.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,16 @@
1111

1212
use OCP\Comments\ICommentsManager;
1313
use OCP\Comments\ICommentsManagerFactory;
14-
use OCP\IServerContainer;
14+
use Psr\Container\ContainerInterface;
1515

1616
class ManagerFactory implements ICommentsManagerFactory {
17-
/**
18-
* Constructor for the comments manager factory
19-
*
20-
* @param IServerContainer $serverContainer server container
21-
*/
2217
public function __construct(
23-
/**
24-
* Server container
25-
*/
26-
private IServerContainer $serverContainer,
18+
private ContainerInterface $serverContainer,
2719
) {
2820
}
2921

30-
/**
31-
* creates and returns an instance of the ICommentsManager
32-
*
33-
* @return ICommentsManager
34-
* @since 9.0.0
35-
*/
3622
#[\Override]
37-
public function getManager() {
23+
public function getManager(): ICommentsManager {
3824
return $this->serverContainer->get(Manager::class);
3925
}
4026
}

lib/private/Contacts/ContactsMenu/ActionProviderStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
use OCP\AppFramework\QueryException;
1818
use OCP\Contacts\ContactsMenu\IBulkProvider;
1919
use OCP\Contacts\ContactsMenu\IProvider;
20-
use OCP\IServerContainer;
2120
use OCP\IUser;
21+
use Psr\Container\ContainerInterface;
2222
use Psr\Log\LoggerInterface;
2323

2424
class ActionProviderStore {
2525
public function __construct(
26-
private IServerContainer $serverContainer,
26+
private ContainerInterface $serverContainer,
2727
private AppManager $appManager,
2828
private LoggerInterface $logger,
2929
) {

lib/private/Http/WellKnown/RequestManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
use OCP\Http\WellKnown\IResponse;
1717
use OCP\Http\WellKnown\JrdResponse;
1818
use OCP\IRequest;
19-
use OCP\IServerContainer;
19+
use Psr\Container\ContainerInterface;
2020
use Psr\Log\LoggerInterface;
2121
use RuntimeException;
2222
use function array_reduce;
2323

2424
class RequestManager {
2525
public function __construct(
2626
private Coordinator $coordinator,
27-
private IServerContainer $container,
27+
private ContainerInterface $container,
2828
private LoggerInterface $logger,
2929
) {
3030
}

lib/private/LDAP/NullLDAPProviderFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
*/
99
namespace OC\LDAP;
1010

11-
use OCP\IServerContainer;
1211
use OCP\LDAP\ILDAPProviderFactory;
12+
use Psr\Container\ContainerInterface;
1313

1414
class NullLDAPProviderFactory implements ILDAPProviderFactory {
15-
public function __construct(IServerContainer $serverContainer) {
15+
public function __construct(ContainerInterface $serverContainer) {
1616
}
1717

1818
#[\Override]

lib/private/Server.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use OC\Activity\EventMerger;
1313
use OC\App\AppManager;
1414
use OC\App\AppStore\Bundles\BundleFetcher;
15-
use OC\AppFramework\Bootstrap\Coordinator;
1615
use OC\AppFramework\Http\Request;
1716
use OC\AppFramework\Http\RequestId;
1817
use OC\AppFramework\Services\AppConfig;
@@ -102,8 +101,6 @@
102101
use OC\OCS\CoreCapabilities;
103102
use OC\OCS\DiscoveryService;
104103
use OC\Preview\Db\PreviewMapper;
105-
use OC\Preview\GeneratorHelper;
106-
use OC\Preview\IMagickSupport;
107104
use OC\Preview\MimeIconProvider;
108105
use OC\Preview\Watcher;
109106
use OC\Preview\WatcherConnector;
@@ -316,6 +313,9 @@ public function __construct(
316313
// To find out if we are running from CLI or not
317314
$this->registerParameter('isCLI', \OC::$CLI);
318315
$this->registerParameter('serverRoot', \OC::$SERVERROOT);
316+
$this->registerService('userId', function (ContainerInterface $c): ?string {
317+
return $c->get(ISession::class)->get('user_id');
318+
});
319319

320320
$this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
321321
return $c;
@@ -343,19 +343,7 @@ public function __construct(
343343
return new View();
344344
}, false);
345345

346-
$this->registerService(IPreview::class, function (ContainerInterface $c) {
347-
return new PreviewManager(
348-
$c->get(IConfig::class),
349-
$c->get(IRootFolder::class),
350-
$c->get(IEventDispatcher::class),
351-
$c->get(GeneratorHelper::class),
352-
$c->get(ISession::class)->get('user_id'),
353-
$c->get(Coordinator::class),
354-
$c->get(IServerContainer::class),
355-
$c->get(IBinaryFinder::class),
356-
$c->get(IMagickSupport::class)
357-
);
358-
});
346+
$this->registerAlias(IPreview::class, PreviewManager::class);
359347
$this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class);
360348

361349
$this->registerService(Watcher::class, function (ContainerInterface $c): Watcher {

lib/private/Settings/Manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use OCP\Group\ISubAdmin;
1313
use OCP\IGroupManager;
1414
use OCP\IL10N;
15-
use OCP\IServerContainer;
1615
use OCP\IURLGenerator;
1716
use OCP\IUser;
1817
use OCP\L10N\IFactory;
@@ -21,6 +20,7 @@
2120
use OCP\Settings\IManager;
2221
use OCP\Settings\ISettings;
2322
use OCP\Settings\ISubAdminSettings;
23+
use Psr\Container\ContainerInterface;
2424
use Psr\Log\LoggerInterface;
2525

2626
class Manager implements IManager {
@@ -42,7 +42,7 @@ public function __construct(
4242
private LoggerInterface $log,
4343
private IFactory $l10nFactory,
4444
private IURLGenerator $url,
45-
private IServerContainer $container,
45+
private ContainerInterface $container,
4646
private AuthorizedGroupMapper $mapper,
4747
private IGroupManager $groupManager,
4848
private ISubAdmin $subAdmin,

0 commit comments

Comments
 (0)