IContainer.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. // use OCP namespace for all classes that are considered public.
  8. // This means that they should be used by apps instead of the internal Nextcloud classes
  9. namespace OCP;
  10. use Closure;
  11. use OCP\AppFramework\QueryException;
  12. use Psr\Container\ContainerExceptionInterface;
  13. use Psr\Container\ContainerInterface;
  14. use Psr\Container\NotFoundExceptionInterface;
  15. /**
  16. * Class IContainer
  17. *
  18. * IContainer is the basic interface to be used for any internal dependency injection mechanism
  19. *
  20. * @since 6.0.0
  21. * @deprecated 20.0.0 use \Psr\Container\ContainerInterface
  22. */
  23. interface IContainer extends ContainerInterface {
  24. /**
  25. * @template T
  26. *
  27. * If a parameter is not registered in the container try to instantiate it
  28. * by using reflection to find out how to build the class
  29. * @param string $name the class name to resolve
  30. * @psalm-param string|class-string<T> $name
  31. * @return \stdClass
  32. * @psalm-return ($name is class-string ? T : mixed)
  33. * @since 8.2.0
  34. * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
  35. * @throws ContainerExceptionInterface if the class could not be found or instantiated
  36. * @throws QueryException if the class could not be found or instantiated
  37. */
  38. public function resolve($name);
  39. /**
  40. * Look up a service for a given name in the container.
  41. *
  42. * @template T
  43. *
  44. * @param string $name
  45. * @psalm-param string|class-string<T> $name
  46. * @param bool $autoload Should we try to autoload the service. If we are trying to resolve built in types this makes no sense for example
  47. * @return mixed
  48. * @psalm-return ($name is class-string ? T : mixed)
  49. * @throws ContainerExceptionInterface if the query could not be resolved
  50. * @throws NotFoundExceptionInterface if the name could not be found within the container
  51. * @throws QueryException if the query could not be resolved
  52. * @since 6.0.0
  53. * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
  54. */
  55. public function query(string $name, bool $autoload = true);
  56. /**
  57. * A value is stored in the container with it's corresponding name
  58. *
  59. * @param string $name
  60. * @param mixed $value
  61. * @return void
  62. * @since 6.0.0
  63. * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerParameter
  64. */
  65. public function registerParameter($name, $value);
  66. /**
  67. * A service is registered in the container where a closure is passed in which will actually
  68. * create the service on demand.
  69. * In case the parameter $shared is set to true (the default usage) the once created service will remain in
  70. * memory and be reused on subsequent calls.
  71. * In case the parameter is false the service will be recreated on every call.
  72. *
  73. * @param string $name
  74. * @param \Closure $closure
  75. * @param bool $shared
  76. * @return void
  77. * @since 6.0.0
  78. * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerService
  79. */
  80. public function registerService($name, Closure $closure, $shared = true);
  81. /**
  82. * Shortcut for returning a service from a service under a different key,
  83. * e.g. to tell the container to return a class when queried for an
  84. * interface
  85. * @param string $alias the alias that should be registered
  86. * @param string $target the target that should be resolved instead
  87. * @since 8.2.0
  88. * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerServiceAlias
  89. */
  90. public function registerAlias($alias, $target);
  91. }