IContainer.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. use Psr\Container\NotFoundExceptionInterface;
  35. /**
  36. * Class IContainer
  37. *
  38. * IContainer is the basic interface to be used for any internal dependency injection mechanism
  39. *
  40. * @since 6.0.0
  41. * @deprecated 20.0.0 use \Psr\Container\ContainerInterface
  42. */
  43. interface IContainer extends ContainerInterface {
  44. /**
  45. * @template T
  46. *
  47. * If a parameter is not registered in the container try to instantiate it
  48. * by using reflection to find out how to build the class
  49. * @param string $name the class name to resolve
  50. * @psalm-param string|class-string<T> $name
  51. * @return \stdClass
  52. * @psalm-return ($name is class-string ? T : mixed)
  53. * @since 8.2.0
  54. * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
  55. * @throws ContainerExceptionInterface if the class could not be found or instantiated
  56. * @throws QueryException if the class could not be found or instantiated
  57. */
  58. public function resolve($name);
  59. /**
  60. * Look up a service for a given name in the container.
  61. *
  62. * @template T
  63. *
  64. * @param string $name
  65. * @psalm-param string|class-string<T> $name
  66. * @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
  67. * @return mixed
  68. * @psalm-return ($name is class-string ? T : mixed)
  69. * @throws ContainerExceptionInterface if the query could not be resolved
  70. * @throws NotFoundExceptionInterface if the name could not be found within the container
  71. * @throws QueryException if the query could not be resolved
  72. * @since 6.0.0
  73. * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
  74. */
  75. public function query(string $name, bool $autoload = true);
  76. /**
  77. * A value is stored in the container with it's corresponding name
  78. *
  79. * @param string $name
  80. * @param mixed $value
  81. * @return void
  82. * @since 6.0.0
  83. * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerParameter
  84. */
  85. public function registerParameter($name, $value);
  86. /**
  87. * A service is registered in the container where a closure is passed in which will actually
  88. * create the service on demand.
  89. * In case the parameter $shared is set to true (the default usage) the once created service will remain in
  90. * memory and be reused on subsequent calls.
  91. * In case the parameter is false the service will be recreated on every call.
  92. *
  93. * @param string $name
  94. * @param \Closure $closure
  95. * @param bool $shared
  96. * @return void
  97. * @since 6.0.0
  98. * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerService
  99. */
  100. public function registerService($name, Closure $closure, $shared = true);
  101. /**
  102. * Shortcut for returning a service from a service under a different key,
  103. * e.g. to tell the container to return a class when queried for an
  104. * interface
  105. * @param string $alias the alias that should be registered
  106. * @param string $target the target that should be resolved instead
  107. * @since 8.2.0
  108. * @deprecated 20.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerServiceAlias
  109. */
  110. public function registerAlias($alias, $target);
  111. }