You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Server.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Carl Schwan <carl@carlschwan.eu>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCP;
  22. use Psr\Container\ContainerExceptionInterface;
  23. use Psr\Container\NotFoundExceptionInterface;
  24. /**
  25. * Class allowing to inject services into your application. You should
  26. * use whenever possible dependency injections instead.
  27. *
  28. * ```php
  29. * use OCP\Server;
  30. *
  31. * $tagManager = Server::get(ITagManager::class);
  32. * ```
  33. *
  34. * @since 25.0.0
  35. */
  36. final class Server {
  37. /**
  38. * @template T
  39. * @param class-string<T>|string $serviceName
  40. * @return T|mixed
  41. * @psalm-template S as class-string<T>|string
  42. * @psalm-param S $serviceName
  43. * @psalm-return (S is class-string<T> ? T : mixed)
  44. * @throws ContainerExceptionInterface
  45. * @throws NotFoundExceptionInterface
  46. * @since 25.0.0
  47. */
  48. public static function get(string $serviceName) {
  49. /** @psalm-suppress UndefinedClass */
  50. return \OC::$server->get($serviceName);
  51. }
  52. }