CapsuleManagerTrait.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Illuminate\Support\Traits;
  3. use Illuminate\Support\Fluent;
  4. use Illuminate\Contracts\Container\Container;
  5. trait CapsuleManagerTrait
  6. {
  7. /**
  8. * The current globally used instance.
  9. *
  10. * @var object
  11. */
  12. protected static $instance;
  13. /**
  14. * The container instance.
  15. *
  16. * @var \Illuminate\Contracts\Container\Container
  17. */
  18. protected $container;
  19. /**
  20. * Setup the IoC container instance.
  21. *
  22. * @param \Illuminate\Contracts\Container\Container $container
  23. * @return void
  24. */
  25. protected function setupContainer(Container $container)
  26. {
  27. $this->container = $container;
  28. if (! $this->container->bound('config')) {
  29. $this->container->instance('config', new Fluent);
  30. }
  31. }
  32. /**
  33. * Make this capsule instance available globally.
  34. *
  35. * @return void
  36. */
  37. public function setAsGlobal()
  38. {
  39. static::$instance = $this;
  40. }
  41. /**
  42. * Get the IoC container instance.
  43. *
  44. * @return \Illuminate\Contracts\Container\Container
  45. */
  46. public function getContainer()
  47. {
  48. return $this->container;
  49. }
  50. /**
  51. * Set the IoC container instance.
  52. *
  53. * @param \Illuminate\Contracts\Container\Container $container
  54. * @return void
  55. */
  56. public function setContainer(Container $container)
  57. {
  58. $this->container = $container;
  59. }
  60. }