Skip to content

Commit da64a3a

Browse files
authored
Merge pull request #31900 from nextcloud/feat/server-container-public
Add a public replacement for OC::$server->get
2 parents b2fa8a0 + f945c0c commit da64a3a

11 files changed

Lines changed: 103 additions & 28 deletions

File tree

apps/files/lib/App.php

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* @author Joas Schilling <coding@schilljs.com>
77
* @author Morris Jobke <hey@morrisjobke.de>
88
* @author Vincent Petry <vincent@nextcloud.com>
9+
* @author Carl Schwan <carl@carlschwan.eu>
910
*
1011
* @license AGPL-3.0
1112
*
@@ -24,37 +25,42 @@
2425
*/
2526
namespace OCA\Files;
2627

28+
use OC\NavigationManager;
29+
use OCP\App\IAppManager;
30+
use OCP\IConfig;
31+
use OCP\IGroupManager;
32+
use OCP\INavigationManager;
33+
use OCP\IURLGenerator;
34+
use OCP\IUserSession;
35+
use OCP\L10N\IFactory;
36+
use OCP\Server;
37+
2738
class App {
28-
/**
29-
* @var \OCP\INavigationManager
30-
*/
31-
private static $navigationManager;
39+
private static ?INavigationManager $navigationManager = null;
3240

3341
/**
3442
* Returns the app's navigation manager
35-
*
36-
* @return \OCP\INavigationManager
3743
*/
38-
public static function getNavigationManager() {
44+
public static function getNavigationManager(): INavigationManager {
3945
// TODO: move this into a service in the Application class
4046
if (self::$navigationManager === null) {
41-
self::$navigationManager = new \OC\NavigationManager(
42-
\OC::$server->getAppManager(),
43-
\OC::$server->getURLGenerator(),
44-
\OC::$server->getL10NFactory(),
45-
\OC::$server->getUserSession(),
46-
\OC::$server->getGroupManager(),
47-
\OC::$server->getConfig()
47+
self::$navigationManager = new NavigationManager(
48+
Server::get(IAppManager::class),
49+
Server::get(IUrlGenerator::class),
50+
Server::get(IFactory::class),
51+
Server::get(IUserSession::class),
52+
Server::get(IGroupManager::class),
53+
Server::get(IConfig::class)
4854
);
4955
self::$navigationManager->clear(false);
5056
}
5157
return self::$navigationManager;
5258
}
5359

54-
public static function extendJsConfig($settings) {
60+
public static function extendJsConfig($settings): void {
5561
$appConfig = json_decode($settings['array']['oc_appconfig'], true);
5662

57-
$maxChunkSize = (int)\OC::$server->getConfig()->getAppValue('files', 'max_chunk_size', 10 * 1024 * 1024);
63+
$maxChunkSize = (int)Server::get(IConfig::class)->getAppValue('files', 'max_chunk_size', (string)(10 * 1024 * 1024));
5864
$appConfig['files'] = [
5965
'max_chunk_size' => $maxChunkSize
6066
];

apps/files/lib/Collaboration/Resources/Listener.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626
namespace OCA\Files\Collaboration\Resources;
2727

28+
use OCP\Server;
2829
use OCP\Collaboration\Resources\IManager;
2930
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
3031

@@ -37,9 +38,9 @@ public static function register(EventDispatcherInterface $dispatcher): void {
3738

3839
public static function shareModification(): void {
3940
/** @var IManager $resourceManager */
40-
$resourceManager = \OC::$server->query(IManager::class);
41+
$resourceManager = Server::get(IManager::class);
4142
/** @var ResourceProvider $resourceProvider */
42-
$resourceProvider = \OC::$server->query(ResourceProvider::class);
43+
$resourceProvider = Server::get(ResourceProvider::class);
4344

4445
$resourceManager->invalidateAccessCacheForProvider($resourceProvider);
4546
}

apps/files/list.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
*
2424
*/
2525
use OCP\Share\IManager;
26+
use OCP\Server;
27+
use OCP\IConfig;
28+
use OCP\IUserSession;
2629

27-
$config = \OC::$server->getConfig();
28-
$userSession = \OC::$server->getUserSession();
30+
$config = Server::get(IConfig::class);
31+
$userSession = Server::get(IUserSession::class);
2932
// TODO: move this to the generated config.js
3033
/** @var IManager $shareManager */
31-
$shareManager = \OC::$server->get(IManager::class);
34+
$shareManager = Server::get(IManager::class);
3235
$publicUploadEnabled = $shareManager->shareApiLinkAllowPublicUpload() ? 'yes' : 'no';
3336

3437
$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', false);

apps/files_external/lib/Lib/Storage/AmazonS3.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use OCP\Files\IMimeTypeDetector;
5454
use OCP\ICacheFactory;
5555
use OCP\IMemcache;
56+
use OCP\Server;
5657

5758
class AmazonS3 extends \OC\Files\Storage\Common {
5859
use S3ConnectionTrait;
@@ -87,9 +88,9 @@ public function __construct($parameters) {
8788
$this->objectCache = new CappedMemoryCache();
8889
$this->directoryCache = new CappedMemoryCache();
8990
$this->filesCache = new CappedMemoryCache();
90-
$this->mimeDetector = \OC::$server->get(IMimeTypeDetector::class);
91+
$this->mimeDetector = Server::get(IMimeTypeDetector::class);
9192
/** @var ICacheFactory $cacheFactory */
92-
$cacheFactory = \OC::$server->get(ICacheFactory::class);
93+
$cacheFactory = Server::get(ICacheFactory::class);
9394
$this->memCache = $cacheFactory->createLocal('s3-external');
9495
}
9596

build/psalm-baseline-ocp.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
<code>$this-&gt;request-&gt;server</code>
2222
</NoInterfaceProperties>
2323
</file>
24+
<file src="lib/public/Server.php">
25+
<InvalidThrow occurrences="2">
26+
<code>ContainerExceptionInterface</code>
27+
</InvalidThrow>
28+
</file>
2429
<file src="lib/public/AppFramework/App.php">
2530
<InternalMethod occurrences="1">
2631
<code>new RouteConfig($this-&gt;container, $router, $routes)</code>

build/psalm-baseline.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,6 @@
11531153
<code>$this-&gt;fileIsEncrypted</code>
11541154
</TypeDoesNotContainType>
11551155
</file>
1156-
<file src="apps/files/lib/App.php">
1157-
<InvalidScalarArgument occurrences="1">
1158-
<code>10 * 1024 * 1024</code>
1159-
</InvalidScalarArgument>
1160-
</file>
11611156
<file src="apps/files/lib/Command/Scan.php">
11621157
<NullArgument occurrences="1">
11631158
<code>null</code>
@@ -4575,6 +4570,11 @@
45754570
<code>is_int($expected)</code>
45764571
</TypeDoesNotContainType>
45774572
</file>
4573+
<file src="lib/public/Server.php">
4574+
<InvalidThrow occurrences="2">
4575+
<code>ContainerExceptionInterface</code>
4576+
</InvalidThrow>
4577+
</file>
45784578
<file src="lib/public/AppFramework/ApiController.php">
45794579
<NoInterfaceProperties occurrences="1">
45804580
<code>$this-&gt;request-&gt;server</code>

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@
515515
'OCP\\Security\\ITrustedDomainHelper' => $baseDir . '/lib/public/Security/ITrustedDomainHelper.php',
516516
'OCP\\Security\\VerificationToken\\IVerificationToken' => $baseDir . '/lib/public/Security/VerificationToken/IVerificationToken.php',
517517
'OCP\\Security\\VerificationToken\\InvalidTokenException' => $baseDir . '/lib/public/Security/VerificationToken/InvalidTokenException.php',
518+
'OCP\\Server' => $baseDir . '/lib/public/Server.php',
518519
'OCP\\Session\\Exceptions\\SessionNotAvailableException' => $baseDir . '/lib/public/Session/Exceptions/SessionNotAvailableException.php',
519520
'OCP\\Settings\\IDelegatedSettings' => $baseDir . '/lib/public/Settings/IDelegatedSettings.php',
520521
'OCP\\Settings\\IIconSection' => $baseDir . '/lib/public/Settings/IIconSection.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
544544
'OCP\\Security\\ITrustedDomainHelper' => __DIR__ . '/../../..' . '/lib/public/Security/ITrustedDomainHelper.php',
545545
'OCP\\Security\\VerificationToken\\IVerificationToken' => __DIR__ . '/../../..' . '/lib/public/Security/VerificationToken/IVerificationToken.php',
546546
'OCP\\Security\\VerificationToken\\InvalidTokenException' => __DIR__ . '/../../..' . '/lib/public/Security/VerificationToken/InvalidTokenException.php',
547+
'OCP\\Server' => __DIR__ . '/../../..' . '/lib/public/Server.php',
547548
'OCP\\Session\\Exceptions\\SessionNotAvailableException' => __DIR__ . '/../../..' . '/lib/public/Session/Exceptions/SessionNotAvailableException.php',
548549
'OCP\\Settings\\IDelegatedSettings' => __DIR__ . '/../../..' . '/lib/public/Settings/IDelegatedSettings.php',
549550
'OCP\\Settings\\IIconSection' => __DIR__ . '/../../..' . '/lib/public/Settings/IIconSection.php',

lib/public/AppFramework/IAppContainer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* thus this interface won't extend it anymore once that was removed. So migrate to the ContainerInterface
3939
* only.
4040
*
41+
* @deprecated 20.0.0
4142
* @since 6.0.0
4243
*/
4344
interface IAppContainer extends ContainerInterface, IContainer {

lib/public/IServerContainer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
* thus this interface won't extend it anymore once that was removed. So migrate to the ContainerInterface
5656
* only.
5757
*
58+
* @deprecated 20.0.0
59+
*
5860
* @since 6.0.0
5961
*/
6062
interface IServerContainer extends ContainerInterface, IContainer {

0 commit comments

Comments
 (0)