Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Events;
4
 
5
use Closure;
6
use Laravel\SerializableClosure\SerializableClosure;
7
 
8
class QueuedClosure
9
{
10
    /**
11
     * The underlying Closure.
12
     *
13
     * @var \Closure
14
     */
15
    public $closure;
16
 
17
    /**
18
     * The name of the connection the job should be sent to.
19
     *
20
     * @var string|null
21
     */
22
    public $connection;
23
 
24
    /**
25
     * The name of the queue the job should be sent to.
26
     *
27
     * @var string|null
28
     */
29
    public $queue;
30
 
31
    /**
32
     * The number of seconds before the job should be made available.
33
     *
34
     * @var \DateTimeInterface|\DateInterval|int|null
35
     */
36
    public $delay;
37
 
38
    /**
39
     * All of the "catch" callbacks for the queued closure.
40
     *
41
     * @var array
42
     */
43
    public $catchCallbacks = [];
44
 
45
    /**
46
     * Create a new queued closure event listener resolver.
47
     *
48
     * @param  \Closure  $closure
49
     * @return void
50
     */
51
    public function __construct(Closure $closure)
52
    {
53
        $this->closure = $closure;
54
    }
55
 
56
    /**
57
     * Set the desired connection for the job.
58
     *
59
     * @param  string|null  $connection
60
     * @return $this
61
     */
62
    public function onConnection($connection)
63
    {
64
        $this->connection = $connection;
65
 
66
        return $this;
67
    }
68
 
69
    /**
70
     * Set the desired queue for the job.
71
     *
72
     * @param  string|null  $queue
73
     * @return $this
74
     */
75
    public function onQueue($queue)
76
    {
77
        $this->queue = $queue;
78
 
79
        return $this;
80
    }
81
 
82
    /**
83
     * Set the desired delay in seconds for the job.
84
     *
85
     * @param  \DateTimeInterface|\DateInterval|int|null  $delay
86
     * @return $this
87
     */
88
    public function delay($delay)
89
    {
90
        $this->delay = $delay;
91
 
92
        return $this;
93
    }
94
 
95
    /**
96
     * Specify a callback that should be invoked if the queued listener job fails.
97
     *
98
     * @param  \Closure  $closure
99
     * @return $this
100
     */
101
    public function catch(Closure $closure)
102
    {
103
        $this->catchCallbacks[] = $closure;
104
 
105
        return $this;
106
    }
107
 
108
    /**
109
     * Resolve the actual event listener callback.
110
     *
111
     * @return \Closure
112
     */
113
    public function resolve()
114
    {
115
        return function (...$arguments) {
116
            dispatch(new CallQueuedListener(InvokeQueuedClosure::class, 'handle', [
117
                'closure' => new SerializableClosure($this->closure),
118
                'arguments' => $arguments,
119
                'catch' => collect($this->catchCallbacks)->map(function ($callback) {
120
                    return new SerializableClosure($callback);
121
                })->all(),
122
            ]))->onConnection($this->connection)->onQueue($this->queue)->delay($this->delay);
123
        };
124
    }
125
}