IContainer.php 3.2 KB

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