aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-04-08 14:16:21 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-05-10 18:51:12 +0200
commitf945c0cbc6aef461fabf17cea42440ad9b6fea09 (patch)
tree73bb7d91d3721049f436ecf160f66c640a805a02
parent0690646d09430ce363b07bc2cd59283e303314eb (diff)
downloadnextcloud-server-f945c0cbc6aef461fabf17cea42440ad9b6fea09.tar.gz
nextcloud-server-f945c0cbc6aef461fabf17cea42440ad9b6fea09.zip
Add a public replacement for OC::$server->get
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
-rw-r--r--apps/files/lib/App.php38
-rw-r--r--apps/files/lib/Collaboration/Resources/Listener.php5
-rw-r--r--apps/files/list.php9
-rw-r--r--apps/files_external/lib/Lib/Storage/AmazonS3.php5
-rw-r--r--build/psalm-baseline-ocp.xml5
-rw-r--r--build/psalm-baseline.xml10
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/public/AppFramework/IAppContainer.php1
-rw-r--r--lib/public/IServerContainer.php2
-rw-r--r--lib/public/Server.php54
11 files changed, 103 insertions, 28 deletions
diff --git a/apps/files/lib/App.php b/apps/files/lib/App.php
index 386e5a3243a..e172f0ae826 100644
--- a/apps/files/lib/App.php
+++ b/apps/files/lib/App.php
@@ -6,6 +6,7 @@
* @author Joas Schilling <coding@schilljs.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Vincent Petry <vincent@nextcloud.com>
+ * @author Carl Schwan <carl@carlschwan.eu>
*
* @license AGPL-3.0
*
@@ -24,37 +25,42 @@
*/
namespace OCA\Files;
+use OC\NavigationManager;
+use OCP\App\IAppManager;
+use OCP\IConfig;
+use OCP\IGroupManager;
+use OCP\INavigationManager;
+use OCP\IURLGenerator;
+use OCP\IUserSession;
+use OCP\L10N\IFactory;
+use OCP\Server;
+
class App {
- /**
- * @var \OCP\INavigationManager
- */
- private static $navigationManager;
+ private static ?INavigationManager $navigationManager = null;
/**
* Returns the app's navigation manager
- *
- * @return \OCP\INavigationManager
*/
- public static function getNavigationManager() {
+ public static function getNavigationManager(): INavigationManager {
// TODO: move this into a service in the Application class
if (self::$navigationManager === null) {
- self::$navigationManager = new \OC\NavigationManager(
- \OC::$server->getAppManager(),
- \OC::$server->getURLGenerator(),
- \OC::$server->getL10NFactory(),
- \OC::$server->getUserSession(),
- \OC::$server->getGroupManager(),
- \OC::$server->getConfig()
+ self::$navigationManager = new NavigationManager(
+ Server::get(IAppManager::class),
+ Server::get(IUrlGenerator::class),
+ Server::get(IFactory::class),
+ Server::get(IUserSession::class),
+ Server::get(IGroupManager::class),
+ Server::get(IConfig::class)
);
self::$navigationManager->clear(false);
}
return self::$navigationManager;
}
- public static function extendJsConfig($settings) {
+ public static function extendJsConfig($settings): void {
$appConfig = json_decode($settings['array']['oc_appconfig'], true);
- $maxChunkSize = (int)\OC::$server->getConfig()->getAppValue('files', 'max_chunk_size', 10 * 1024 * 1024);
+ $maxChunkSize = (int)Server::get(IConfig::class)->getAppValue('files', 'max_chunk_size', (string)(10 * 1024 * 1024));
$appConfig['files'] = [
'max_chunk_size' => $maxChunkSize
];
diff --git a/apps/files/lib/Collaboration/Resources/Listener.php b/apps/files/lib/Collaboration/Resources/Listener.php
index 5cf84316578..64dd693a4da 100644
--- a/apps/files/lib/Collaboration/Resources/Listener.php
+++ b/apps/files/lib/Collaboration/Resources/Listener.php
@@ -25,6 +25,7 @@ declare(strict_types=1);
*/
namespace OCA\Files\Collaboration\Resources;
+use OCP\Server;
use OCP\Collaboration\Resources\IManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -37,9 +38,9 @@ class Listener {
public static function shareModification(): void {
/** @var IManager $resourceManager */
- $resourceManager = \OC::$server->query(IManager::class);
+ $resourceManager = Server::get(IManager::class);
/** @var ResourceProvider $resourceProvider */
- $resourceProvider = \OC::$server->query(ResourceProvider::class);
+ $resourceProvider = Server::get(ResourceProvider::class);
$resourceManager->invalidateAccessCacheForProvider($resourceProvider);
}
diff --git a/apps/files/list.php b/apps/files/list.php
index 09dc217139c..c4b93b2e145 100644
--- a/apps/files/list.php
+++ b/apps/files/list.php
@@ -23,12 +23,15 @@
*
*/
use OCP\Share\IManager;
+use OCP\Server;
+use OCP\IConfig;
+use OCP\IUserSession;
-$config = \OC::$server->getConfig();
-$userSession = \OC::$server->getUserSession();
+$config = Server::get(IConfig::class);
+$userSession = Server::get(IUserSession::class);
// TODO: move this to the generated config.js
/** @var IManager $shareManager */
-$shareManager = \OC::$server->get(IManager::class);
+$shareManager = Server::get(IManager::class);
$publicUploadEnabled = $shareManager->shareApiLinkAllowPublicUpload() ? 'yes' : 'no';
$showgridview = $config->getUserValue($userSession->getUser()->getUID(), 'files', 'show_grid', false);
diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php
index cfd78689fa4..d3e9605e5a1 100644
--- a/apps/files_external/lib/Lib/Storage/AmazonS3.php
+++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php
@@ -53,6 +53,7 @@ use OCP\Files\FileInfo;
use OCP\Files\IMimeTypeDetector;
use OCP\ICacheFactory;
use OCP\IMemcache;
+use OCP\Server;
class AmazonS3 extends \OC\Files\Storage\Common {
use S3ConnectionTrait;
@@ -87,9 +88,9 @@ class AmazonS3 extends \OC\Files\Storage\Common {
$this->objectCache = new CappedMemoryCache();
$this->directoryCache = new CappedMemoryCache();
$this->filesCache = new CappedMemoryCache();
- $this->mimeDetector = \OC::$server->get(IMimeTypeDetector::class);
+ $this->mimeDetector = Server::get(IMimeTypeDetector::class);
/** @var ICacheFactory $cacheFactory */
- $cacheFactory = \OC::$server->get(ICacheFactory::class);
+ $cacheFactory = Server::get(ICacheFactory::class);
$this->memCache = $cacheFactory->createLocal('s3-external');
}
diff --git a/build/psalm-baseline-ocp.xml b/build/psalm-baseline-ocp.xml
index 87a994ea720..5490f505886 100644
--- a/build/psalm-baseline-ocp.xml
+++ b/build/psalm-baseline-ocp.xml
@@ -21,6 +21,11 @@
<code>$this-&gt;request-&gt;server</code>
</NoInterfaceProperties>
</file>
+ <file src="lib/public/Server.php">
+ <InvalidThrow occurrences="2">
+ <code>ContainerExceptionInterface</code>
+ </InvalidThrow>
+ </file>
<file src="lib/public/AppFramework/App.php">
<InternalMethod occurrences="1">
<code>new RouteConfig($this-&gt;container, $router, $routes)</code>
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml
index 4f4e18e1f90..7152a3fbffe 100644
--- a/build/psalm-baseline.xml
+++ b/build/psalm-baseline.xml
@@ -1153,11 +1153,6 @@
<code>$this-&gt;fileIsEncrypted</code>
</TypeDoesNotContainType>
</file>
- <file src="apps/files/lib/App.php">
- <InvalidScalarArgument occurrences="1">
- <code>10 * 1024 * 1024</code>
- </InvalidScalarArgument>
- </file>
<file src="apps/files/lib/Command/Scan.php">
<NullArgument occurrences="1">
<code>null</code>
@@ -4575,6 +4570,11 @@
<code>is_int($expected)</code>
</TypeDoesNotContainType>
</file>
+ <file src="lib/public/Server.php">
+ <InvalidThrow occurrences="2">
+ <code>ContainerExceptionInterface</code>
+ </InvalidThrow>
+ </file>
<file src="lib/public/AppFramework/ApiController.php">
<NoInterfaceProperties occurrences="1">
<code>$this-&gt;request-&gt;server</code>
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 997c5d5a844..32a4c749a08 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -515,6 +515,7 @@ return array(
'OCP\\Security\\ITrustedDomainHelper' => $baseDir . '/lib/public/Security/ITrustedDomainHelper.php',
'OCP\\Security\\VerificationToken\\IVerificationToken' => $baseDir . '/lib/public/Security/VerificationToken/IVerificationToken.php',
'OCP\\Security\\VerificationToken\\InvalidTokenException' => $baseDir . '/lib/public/Security/VerificationToken/InvalidTokenException.php',
+ 'OCP\\Server' => $baseDir . '/lib/public/Server.php',
'OCP\\Session\\Exceptions\\SessionNotAvailableException' => $baseDir . '/lib/public/Session/Exceptions/SessionNotAvailableException.php',
'OCP\\Settings\\IDelegatedSettings' => $baseDir . '/lib/public/Settings/IDelegatedSettings.php',
'OCP\\Settings\\IIconSection' => $baseDir . '/lib/public/Settings/IIconSection.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index c6cfdaba6ec..8f2b1cb648a 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -544,6 +544,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Security\\ITrustedDomainHelper' => __DIR__ . '/../../..' . '/lib/public/Security/ITrustedDomainHelper.php',
'OCP\\Security\\VerificationToken\\IVerificationToken' => __DIR__ . '/../../..' . '/lib/public/Security/VerificationToken/IVerificationToken.php',
'OCP\\Security\\VerificationToken\\InvalidTokenException' => __DIR__ . '/../../..' . '/lib/public/Security/VerificationToken/InvalidTokenException.php',
+ 'OCP\\Server' => __DIR__ . '/../../..' . '/lib/public/Server.php',
'OCP\\Session\\Exceptions\\SessionNotAvailableException' => __DIR__ . '/../../..' . '/lib/public/Session/Exceptions/SessionNotAvailableException.php',
'OCP\\Settings\\IDelegatedSettings' => __DIR__ . '/../../..' . '/lib/public/Settings/IDelegatedSettings.php',
'OCP\\Settings\\IIconSection' => __DIR__ . '/../../..' . '/lib/public/Settings/IIconSection.php',
diff --git a/lib/public/AppFramework/IAppContainer.php b/lib/public/AppFramework/IAppContainer.php
index 626481de0e0..a3b82144033 100644
--- a/lib/public/AppFramework/IAppContainer.php
+++ b/lib/public/AppFramework/IAppContainer.php
@@ -38,6 +38,7 @@ use Psr\Container\ContainerInterface;
* thus this interface won't extend it anymore once that was removed. So migrate to the ContainerInterface
* only.
*
+ * @deprecated 20.0.0
* @since 6.0.0
*/
interface IAppContainer extends ContainerInterface, IContainer {
diff --git a/lib/public/IServerContainer.php b/lib/public/IServerContainer.php
index 024abbe2a97..6c07a5218ba 100644
--- a/lib/public/IServerContainer.php
+++ b/lib/public/IServerContainer.php
@@ -55,6 +55,8 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
* thus this interface won't extend it anymore once that was removed. So migrate to the ContainerInterface
* only.
*
+ * @deprecated 20.0.0
+ *
* @since 6.0.0
*/
interface IServerContainer extends ContainerInterface, IContainer {
diff --git a/lib/public/Server.php b/lib/public/Server.php
new file mode 100644
index 00000000000..be6b6a49236
--- /dev/null
+++ b/lib/public/Server.php
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Carl Schwan <carl@carlschwan.eu>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCP;
+
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
+
+/**
+ * Class allowing to inject services into your application. You should
+ * use whenever possible dependency injections instead.
+ *
+ * ```php
+ * use OCP\Server;
+ *
+ * $tagManager = Server::get(ITagManager::class);
+ * ```
+ *
+ * @since 25.0.0
+ */
+final class Server {
+ /**
+ * @template T
+ * @param class-string<T>|string $serviceName
+ * @return T|mixed
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @since 25.0.0
+ */
+ public static function get(string $serviceName) {
+ /** @psalm-suppress UndefinedClass */
+ return \OC::$server->get($serviceName);
+ }
+}