* @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
*
*/
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
];
*/
namespace OCA\Files\Collaboration\Resources;
+use OCP\Server;
use OCP\Collaboration\Resources\IManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
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);
}
*
*/
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);
use OCP\Files\IMimeTypeDetector;
use OCP\ICacheFactory;
use OCP\IMemcache;
+use OCP\Server;
class AmazonS3 extends \OC\Files\Storage\Common {
use S3ConnectionTrait;
$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');
}
<code>$this->request->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->container, $router, $routes)</code>
<code>$this->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>
<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->request->server</code>
'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',
'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',
* 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 {
* 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 {
--- /dev/null
+<?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);
+ }
+}