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/public | |
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/public')
-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 |
3 files changed, 57 insertions, 0 deletions
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); + } +} |