Server.php 999 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP;
  8. use Psr\Container\ContainerExceptionInterface;
  9. use Psr\Container\NotFoundExceptionInterface;
  10. /**
  11. * Class allowing to inject services into your application. You should
  12. * use whenever possible dependency injections instead.
  13. *
  14. * ```php
  15. * use OCP\Server;
  16. *
  17. * $tagManager = Server::get(ITagManager::class);
  18. * ```
  19. *
  20. * @since 25.0.0
  21. */
  22. final class Server {
  23. /**
  24. * @template T
  25. * @param class-string<T>|string $serviceName
  26. * @return T|mixed
  27. * @psalm-template S as class-string<T>|string
  28. * @psalm-param S $serviceName
  29. * @psalm-return (S is class-string<T> ? T : mixed)
  30. * @throws ContainerExceptionInterface
  31. * @throws NotFoundExceptionInterface
  32. * @since 25.0.0
  33. */
  34. public static function get(string $serviceName) {
  35. /** @psalm-suppress UndefinedClass */
  36. return \OC::$server->get($serviceName);
  37. }
  38. }