View file vendor/laravel/framework/src/Illuminate/Foundation/Bus/Dispatchable.php

File size: 2.45Kb
  1. <?php
  2.  
  3. namespace Illuminate\Foundation\Bus;
  4.  
  5. use Illuminate\Contracts\Bus\Dispatcher;
  6. use Illuminate\Support\Fluent;
  7.  
  8. trait Dispatchable
  9. {
  10. /**
  11. * Dispatch the job with the given arguments.
  12. *
  13. * @return \Illuminate\Foundation\Bus\PendingDispatch
  14. */
  15. public static function dispatch()
  16. {
  17. return new PendingDispatch(new static(...func_get_args()));
  18. }
  19.  
  20. /**
  21. * Dispatch the job with the given arguments if the given truth test passes.
  22. *
  23. * @param bool $boolean
  24. * @param mixed ...$arguments
  25. * @return \Illuminate\Foundation\Bus\PendingDispatch|\Illuminate\Support\Fluent
  26. */
  27. public static function dispatchIf($boolean, ...$arguments)
  28. {
  29. return $boolean
  30. ? new PendingDispatch(new static(...$arguments))
  31. : new Fluent;
  32. }
  33.  
  34. /**
  35. * Dispatch the job with the given arguments unless the given truth test passes.
  36. *
  37. * @param bool $boolean
  38. * @param mixed ...$arguments
  39. * @return \Illuminate\Foundation\Bus\PendingDispatch|\Illuminate\Support\Fluent
  40. */
  41. public static function dispatchUnless($boolean, ...$arguments)
  42. {
  43. return ! $boolean
  44. ? new PendingDispatch(new static(...$arguments))
  45. : new Fluent;
  46. }
  47.  
  48. /**
  49. * Dispatch a command to its appropriate handler in the current process.
  50. *
  51. * Queueable jobs will be dispatched to the "sync" queue.
  52. *
  53. * @return mixed
  54. */
  55. public static function dispatchSync()
  56. {
  57. return app(Dispatcher::class)->dispatchSync(new static(...func_get_args()));
  58. }
  59.  
  60. /**
  61. * Dispatch a command to its appropriate handler in the current process.
  62. *
  63. * @return mixed
  64. *
  65. * @deprecated Will be removed in a future Laravel version.
  66. */
  67. public static function dispatchNow()
  68. {
  69. return app(Dispatcher::class)->dispatchNow(new static(...func_get_args()));
  70. }
  71.  
  72. /**
  73. * Dispatch a command to its appropriate handler after the current process.
  74. *
  75. * @return mixed
  76. */
  77. public static function dispatchAfterResponse()
  78. {
  79. return app(Dispatcher::class)->dispatchAfterResponse(new static(...func_get_args()));
  80. }
  81.  
  82. /**
  83. * Set the jobs that should run if this job is successful.
  84. *
  85. * @param array $chain
  86. * @return \Illuminate\Foundation\Bus\PendingChain
  87. */
  88. public static function withChain($chain)
  89. {
  90. return new PendingChain(static::class, $chain);
  91. }
  92. }