Container.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace Illuminate\Contracts\Container;
  3. use Closure;
  4. use Psr\Container\ContainerInterface;
  5. interface Container extends ContainerInterface
  6. {
  7. /**
  8. * Determine if the given abstract type has been bound.
  9. *
  10. * @param string $abstract
  11. * @return bool
  12. */
  13. public function bound($abstract);
  14. /**
  15. * Alias a type to a different name.
  16. *
  17. * @param string $abstract
  18. * @param string $alias
  19. * @return void
  20. *
  21. * @throws \LogicException
  22. */
  23. public function alias($abstract, $alias);
  24. /**
  25. * Assign a set of tags to a given binding.
  26. *
  27. * @param array|string $abstracts
  28. * @param array|mixed ...$tags
  29. * @return void
  30. */
  31. public function tag($abstracts, $tags);
  32. /**
  33. * Resolve all of the bindings for a given tag.
  34. *
  35. * @param string $tag
  36. * @return iterable
  37. */
  38. public function tagged($tag);
  39. /**
  40. * Register a binding with the container.
  41. *
  42. * @param string $abstract
  43. * @param \Closure|string|null $concrete
  44. * @param bool $shared
  45. * @return void
  46. */
  47. public function bind($abstract, $concrete = null, $shared = false);
  48. /**
  49. * Register a binding if it hasn't already been registered.
  50. *
  51. * @param string $abstract
  52. * @param \Closure|string|null $concrete
  53. * @param bool $shared
  54. * @return void
  55. */
  56. public function bindIf($abstract, $concrete = null, $shared = false);
  57. /**
  58. * Register a shared binding in the container.
  59. *
  60. * @param string $abstract
  61. * @param \Closure|string|null $concrete
  62. * @return void
  63. */
  64. public function singleton($abstract, $concrete = null);
  65. /**
  66. * Register a shared binding if it hasn't already been registered.
  67. *
  68. * @param string $abstract
  69. * @param \Closure|string|null $concrete
  70. * @return void
  71. */
  72. public function singletonIf($abstract, $concrete = null);
  73. /**
  74. * "Extend" an abstract type in the container.
  75. *
  76. * @param string $abstract
  77. * @param \Closure $closure
  78. * @return void
  79. *
  80. * @throws \InvalidArgumentException
  81. */
  82. public function extend($abstract, Closure $closure);
  83. /**
  84. * Register an existing instance as shared in the container.
  85. *
  86. * @param string $abstract
  87. * @param mixed $instance
  88. * @return mixed
  89. */
  90. public function instance($abstract, $instance);
  91. /**
  92. * Add a contextual binding to the container.
  93. *
  94. * @param string $concrete
  95. * @param string $abstract
  96. * @param \Closure|string $implementation
  97. * @return void
  98. */
  99. public function addContextualBinding($concrete, $abstract, $implementation);
  100. /**
  101. * Define a contextual binding.
  102. *
  103. * @param string|array $concrete
  104. * @return \Illuminate\Contracts\Container\ContextualBindingBuilder
  105. */
  106. public function when($concrete);
  107. /**
  108. * Get a closure to resolve the given type from the container.
  109. *
  110. * @param string $abstract
  111. * @return \Closure
  112. */
  113. public function factory($abstract);
  114. /**
  115. * Flush the container of all bindings and resolved instances.
  116. *
  117. * @return void
  118. */
  119. public function flush();
  120. /**
  121. * Resolve the given type from the container.
  122. *
  123. * @param string $abstract
  124. * @param array $parameters
  125. * @return mixed
  126. *
  127. * @throws \Illuminate\Contracts\Container\BindingResolutionException
  128. */
  129. public function make($abstract, array $parameters = []);
  130. /**
  131. * Call the given Closure / class@method and inject its dependencies.
  132. *
  133. * @param callable|string $callback
  134. * @param array $parameters
  135. * @param string|null $defaultMethod
  136. * @return mixed
  137. */
  138. public function call($callback, array $parameters = [], $defaultMethod = null);
  139. /**
  140. * Determine if the given abstract type has been resolved.
  141. *
  142. * @param string $abstract
  143. * @return bool
  144. */
  145. public function resolved($abstract);
  146. /**
  147. * Register a new resolving callback.
  148. *
  149. * @param \Closure|string $abstract
  150. * @param \Closure|null $callback
  151. * @return void
  152. */
  153. public function resolving($abstract, Closure $callback = null);
  154. /**
  155. * Register a new after resolving callback.
  156. *
  157. * @param \Closure|string $abstract
  158. * @param \Closure|null $callback
  159. * @return void
  160. */
  161. public function afterResolving($abstract, Closure $callback = null);
  162. }