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