diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-04-08 14:16:21 +0200 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-05-10 18:51:12 +0200 |
commit | f945c0cbc6aef461fabf17cea42440ad9b6fea09 (patch) | |
tree | 73bb7d91d3721049f436ecf160f66c640a805a02 /lib | |
parent | 0690646d09430ce363b07bc2cd59283e303314eb (diff) | |
download | nextcloud-server-f945c0cbc6aef461fabf17cea42440ad9b6fea09.tar.gz nextcloud-server-f945c0cbc6aef461fabf17cea42440ad9b6fea09.zip |
Add a public replacement for OC::$server->get
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/public/AppFramework/IAppContainer.php | 1 | ||||
-rw-r--r-- | lib/public/IServerContainer.php | 2 | ||||
-rw-r--r-- | lib/public/Server.php | 54 |
5 files changed, 59 insertions, 0 deletions
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); + } +} |