Server.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. * @template S as class-string<T>|string
  40. * @param S $serviceName
  41. * @return (S is class-string<T> ? T : mixed)
  42. * @throws ContainerExceptionInterface
  43. * @throws NotFoundExceptionInterface
  44. * @since 25.0.0
  45. */
  46. public static function get(string $serviceName) {
  47. /** @psalm-suppress UndefinedClass */
  48. return \OC::$server->get($serviceName);
  49. }
  50. }