IContainer.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. * @since 6.0.0
  59. */
  60. public function query($name);
  61. /**
  62. * A value is stored in the container with it's corresponding name
  63. *
  64. * @param string $name
  65. * @param mixed $value
  66. * @return void
  67. * @since 6.0.0
  68. */
  69. public function registerParameter($name, $value);
  70. /**
  71. * A service is registered in the container where a closure is passed in which will actually
  72. * create the service on demand.
  73. * In case the parameter $shared is set to true (the default usage) the once created service will remain in
  74. * memory and be reused on subsequent calls.
  75. * In case the parameter is false the service will be recreated on every call.
  76. *
  77. * @param string $name
  78. * @param \Closure $closure
  79. * @param bool $shared
  80. * @return void
  81. * @since 6.0.0
  82. */
  83. public function registerService($name, Closure $closure, $shared = true);
  84. /**
  85. * Shortcut for returning a service from a service under a different key,
  86. * e.g. to tell the container to return a class when queried for an
  87. * interface
  88. * @param string $alias the alias that should be registered
  89. * @param string $target the target that should be resolved instead
  90. * @since 8.2.0
  91. */
  92. public function registerAlias($alias, $target);
  93. }