-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDispatchable.php
More file actions
68 lines (61 loc) · 1.62 KB
/
Copy pathDispatchable.php
File metadata and controls
68 lines (61 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Dispatchable class file.
*
* @package Mantle
*/
namespace Mantle\Queue;
use Mantle\Contracts\Queue\Dispatcher;
/**
* Allow a job to be dispatchable.
*/
trait Dispatchable {
/**
* Dispatch the job with the given arguments.
*
* @param mixed ...$args Arguments passed to the job.
*/
public static function dispatch( ...$args ): Pending_Dispatch {
return new Pending_Dispatch( new static( ...$args ) );
}
/**
* Dispatch the job with the given arguments if the given truth test passes.
*
* @param bool $boolean Truth check.
* @param mixed ...$args Dispatch arguments.
* @return Pending_Dispatch|false
*/
public static function dispatch_if( $boolean, ...$args ): Pending_Dispatch|bool {
return $boolean ? static::dispatch( ...$args ) : false;
}
/**
* Dispatch the job with the given arguments if the given truth test passes.
*
* @param bool $boolean Truth check.
* @param mixed ...$args Dispatch arguments.
* @return Pending_Dispatch|false
*/
public static function dispatch_unless( $boolean, ...$args ): Pending_Dispatch|bool {
return $boolean ? false : static::dispatch( ...$args );
}
/**
* Dispatch a job now given the current arguments.
*
* @param mixed ...$args Dispatch arguments.
*/
public static function dispatch_now( ...$args ): void {
app( Dispatcher::class )->dispatch_now(
new static( ...$args )
);
}
/**
* Dispatch after sending the response.
*
* @param mixed ...$args Dispatch arguments.
*/
public static function dispatch_after_response( ...$args ): void {
app( Dispatcher::class )->dispatch_after_response(
new static( ...$args )
);
}
}