Container.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. * Register a scoped binding in the container.
  75. *
  76. * @param string $abstract
  77. * @param \Closure|string|null $concrete
  78. * @return void
  79. */
  80. public function scoped($abstract, $concrete = null);
  81. /**
  82. * Register a scoped binding if it hasn't already been registered.
  83. *
  84. * @param string $abstract
  85. * @param \Closure|string|null $concrete
  86. * @return void
  87. */
  88. public function scopedIf($abstract, $concrete = null);
  89. /**
  90. * "Extend" an abstract type in the container.
  91. *
  92. * @param string $abstract
  93. * @param \Closure $closure
  94. * @return void
  95. *
  96. * @throws \InvalidArgumentException
  97. */
  98. public function extend($abstract, Closure $closure);
  99. /**
  100. * Register an existing instance as shared in the container.
  101. *
  102. * @param string $abstract
  103. * @param mixed $instance
  104. * @return mixed
  105. */
  106. public function instance($abstract, $instance);
  107. /**
  108. * Add a contextual binding to the container.
  109. *
  110. * @param string $concrete
  111. * @param string $abstract
  112. * @param \Closure|string $implementation
  113. * @return void
  114. */
  115. public function addContextualBinding($concrete, $abstract, $implementation);
  116. /**
  117. * Define a contextual binding.
  118. *
  119. * @param string|array $concrete
  120. * @return \Illuminate\Contracts\Container\ContextualBindingBuilder
  121. */
  122. public function when($concrete);
  123. /**
  124. * Get a closure to resolve the given type from the container.
  125. *
  126. * @param string $abstract
  127. * @return \Closure
  128. */
  129. public function factory($abstract);
  130. /**
  131. * Flush the container of all bindings and resolved instances.
  132. *
  133. * @return void
  134. */
  135. public function flush();
  136. /**
  137. * Resolve the given type from the container.
  138. *
  139. * @param string $abstract
  140. * @param array $parameters
  141. * @return mixed
  142. *
  143. * @throws \Illuminate\Contracts\Container\BindingResolutionException
  144. */
  145. public function make($abstract, array $parameters = []);
  146. /**
  147. * Call the given Closure / class@method and inject its dependencies.
  148. *
  149. * @param callable|string $callback
  150. * @param array $parameters
  151. * @param string|null $defaultMethod
  152. * @return mixed
  153. */
  154. public function call($callback, array $parameters = [], $defaultMethod = null);
  155. /**
  156. * Determine if the given abstract type has been resolved.
  157. *
  158. * @param string $abstract
  159. * @return bool
  160. */
  161. public function resolved($abstract);
  162. /**
  163. * Register a new before resolving callback.
  164. *
  165. * @param \Closure|string $abstract
  166. * @param \Closure|null $callback
  167. * @return void
  168. */
  169. public function beforeResolving($abstract, Closure $callback = null);
  170. /**
  171. * Register a new resolving callback.
  172. *
  173. * @param \Closure|string $abstract
  174. * @param \Closure|null $callback
  175. * @return void
  176. */
  177. public function resolving($abstract, Closure $callback = null);
  178. /**
  179. * Register a new after resolving callback.
  180. *
  181. * @param \Closure|string $abstract
  182. * @param \Closure|null $callback
  183. * @return void
  184. */
  185. public function afterResolving($abstract, Closure $callback = null);
  186. }