Bus.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Illuminate\Support\Facades;
  3. use Illuminate\Contracts\Bus\Dispatcher as BusDispatcherContract;
  4. use Illuminate\Foundation\Bus\PendingChain;
  5. use Illuminate\Support\Testing\Fakes\BusFake;
  6. /**
  7. * @method static \Illuminate\Bus\Batch|null findBatch(string $batchId)
  8. * @method static \Illuminate\Bus\PendingBatch batch(array|mixed $jobs)
  9. * @method static \Illuminate\Contracts\Bus\Dispatcher map(array $map)
  10. * @method static \Illuminate\Contracts\Bus\Dispatcher pipeThrough(array $pipes)
  11. * @method static \Illuminate\Foundation\Bus\PendingChain chain(array $jobs)
  12. * @method static bool hasCommandHandler($command)
  13. * @method static bool|mixed getCommandHandler($command)
  14. * @method static mixed dispatch($command)
  15. * @method static mixed dispatchNow($command, $handler = null)
  16. * @method static mixed dispatchSync($command, $handler = null)
  17. * @method static void assertDispatched(string|\Closure $command, callable|int $callback = null)
  18. * @method static void assertDispatchedTimes(string $command, int $times = 1)
  19. * @method static void assertNotDispatched(string|\Closure $command, callable|int $callback = null)
  20. * @method static void assertDispatchedAfterResponse(string|\Closure $command, callable|int $callback = null)
  21. * @method static void assertDispatchedAfterResponseTimes(string $command, int $times = 1)
  22. * @method static void assertNotDispatchedAfterResponse(string|\Closure $command, callable $callback = null)
  23. * @method static void assertBatched(callable $callback)
  24. * @method static void assertBatchCount(int $count)
  25. * @method static void assertChained(array $expectedChain)
  26. * @method static void assertDispatchedSync(string|\Closure $command, callable $callback = null)
  27. * @method static void assertDispatchedSyncTimes(string $command, int $times = 1)
  28. * @method static void assertNotDispatchedSync(string|\Closure $command, callable $callback = null)
  29. * @method static void assertDispatchedWithoutChain(string|\Closure $command, callable $callback = null)
  30. *
  31. * @see \Illuminate\Contracts\Bus\Dispatcher
  32. */
  33. class Bus extends Facade
  34. {
  35. /**
  36. * Replace the bound instance with a fake.
  37. *
  38. * @param array|string $jobsToFake
  39. * @return \Illuminate\Support\Testing\Fakes\BusFake
  40. */
  41. public static function fake($jobsToFake = [])
  42. {
  43. static::swap($fake = new BusFake(static::getFacadeRoot(), $jobsToFake));
  44. return $fake;
  45. }
  46. /**
  47. * Dispatch the given chain of jobs.
  48. *
  49. * @param array|mixed $jobs
  50. * @return \Illuminate\Foundation\Bus\PendingDispatch
  51. */
  52. public static function dispatchChain($jobs)
  53. {
  54. $jobs = is_array($jobs) ? $jobs : func_get_args();
  55. return (new PendingChain(array_shift($jobs), $jobs))
  56. ->dispatch();
  57. }
  58. /**
  59. * Get the registered name of the component.
  60. *
  61. * @return string
  62. */
  63. protected static function getFacadeAccessor()
  64. {
  65. return BusDispatcherContract::class;
  66. }
  67. }