Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 399 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

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