IContainer.php 3.3 KB

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