IContainer.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. // use OCP namespace for all classes that are considered public.
  28. // This means that they should be used by apps instead of the internal ownCloud classes
  29. namespace OCP;
  30. use Closure;
  31. use OCP\AppFramework\QueryException;
  32. use Psr\Container\ContainerExceptionInterface;
  33. use Psr\Container\ContainerInterface;
  34. /**
  35. * Class IContainer
  36. *
  37. * IContainer is the basic interface to be used for any internal dependency injection mechanism
  38. *
  39. * @since 6.0.0
  40. * @deprecated 20.0.0 use \Psr\Container\ContainerInterface
  41. */
  42. interface IContainer extends ContainerInterface {
  43. /**
  44. * @template T
  45. *
  46. * If a parameter is not registered in the container try to instantiate it
  47. * by using reflection to find out how to build the class
  48. * @param string $name the class name to resolve
  49. * @psalm-param string|class-string<T> $name
  50. * @return \stdClass
  51. * @psalm-return ($name is class-string ? T : mixed)
  52. * @since 8.2.0
  53. * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
  54. * @throws ContainerExceptionInterface if the class could not be found or instantiated
  55. * @throws QueryException if the class could not be found or instantiated
  56. */
  57. public function resolve($name);
  58. /**
  59. * Look up a service for a given name in the container.
  60. *
  61. * @template T
  62. *
  63. * @param string $name
  64. * @psalm-param string|class-string<T> $name
  65. * @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
  66. * @return mixed
  67. * @psalm-return ($name is class-string ? T : mixed)
  68. * @throws ContainerExceptionInterface if the query could not be resolved
  69. * @throws QueryException if the query could not be resolved
  70. * @since 6.0.0
  71. * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
  72. */
  73. public function query(string $name, bool $autoload = true);
  74. /**
  75. * A value is stored in the container with it's corresponding name
  76. *
  77. * @param string $name
  78. * @param mixed $value
  79. * @return void
  80. * @since 6.0.0
  81. * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerParameter
  82. */
  83. public function registerParameter($name, $value);
  84. /**
  85. * A service is registered in the container where a closure is passed in which will actually
  86. * create the service on demand.
  87. * In case the parameter $shared is set to true (the default usage) the once created service will remain in
  88. * memory and be reused on subsequent calls.
  89. * In case the parameter is false the service will be recreated on every call.
  90. *
  91. * @param string $name
  92. * @param \Closure $closure
  93. * @param bool $shared
  94. * @return void
  95. * @since 6.0.0
  96. * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerService
  97. */
  98. public function registerService($name, Closure $closure, $shared = true);
  99. /**
  100. * Shortcut for returning a service from a service under a different key,
  101. * e.g. to tell the container to return a class when queried for an
  102. * interface
  103. * @param string $alias the alias that should be registered
  104. * @param string $target the target that should be resolved instead
  105. * @since 8.2.0
  106. * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerServiceAlias
  107. */
  108. public function registerAlias($alias, $target);
  109. }