IContainer.php 3.0 KB

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