BusServiceProvider.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Illuminate\Bus;
  3. use Illuminate\Support\ServiceProvider;
  4. use Illuminate\Contracts\Bus\Dispatcher as DispatcherContract;
  5. use Illuminate\Contracts\Queue\Factory as QueueFactoryContract;
  6. use Illuminate\Contracts\Bus\QueueingDispatcher as QueueingDispatcherContract;
  7. class BusServiceProvider extends ServiceProvider
  8. {
  9. /**
  10. * Indicates if loading of the provider is deferred.
  11. *
  12. * @var bool
  13. */
  14. protected $defer = true;
  15. /**
  16. * Register the service provider.
  17. *
  18. * @return void
  19. */
  20. public function register()
  21. {
  22. $this->app->singleton(Dispatcher::class, function ($app) {
  23. return new Dispatcher($app, function ($connection = null) use ($app) {
  24. return $app[QueueFactoryContract::class]->connection($connection);
  25. });
  26. });
  27. $this->app->alias(
  28. Dispatcher::class, DispatcherContract::class
  29. );
  30. $this->app->alias(
  31. Dispatcher::class, QueueingDispatcherContract::class
  32. );
  33. }
  34. /**
  35. * Get the services provided by the provider.
  36. *
  37. * @return array
  38. */
  39. public function provides()
  40. {
  41. return [
  42. Dispatcher::class,
  43. DispatcherContract::class,
  44. QueueingDispatcherContract::class,
  45. ];
  46. }
  47. }