|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Abstract class for Delayed_Event |
|
7
|
|
|
* |
|
8
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
9
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
11
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
12
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
13
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
14
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
15
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
16
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
17
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
18
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Glynn Quelch <[email protected]> |
|
21
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
|
22
|
|
|
* @package PinkCrab\Queue |
|
23
|
|
|
* @since 0.1.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace PinkCrab\Queue\Event; |
|
27
|
|
|
|
|
28
|
|
|
use DateTimeImmutable; |
|
29
|
|
|
|
|
30
|
|
|
abstract class Delayed_Event implements Event { |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The event name (Hook) |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $hook; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The queue group it belongs to |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $group = ''; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The data to be passed to the event |
|
48
|
|
|
* |
|
49
|
|
|
* @var mixed[]|null |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $data = array(); |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Denotes if the event is unique or not |
|
55
|
|
|
* |
|
56
|
|
|
* @var bool |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $is_unique = false; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the group for the event. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
final public function get_group(): string { |
|
66
|
|
|
return $this->group; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get the hook for the event. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
final public function get_hook(): string { |
|
75
|
|
|
return $this->hook; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Get the data for the event. |
|
80
|
|
|
* |
|
81
|
|
|
* @return mixed[]|null |
|
82
|
|
|
*/ |
|
83
|
|
|
final public function get_data(): ?array { |
|
84
|
|
|
return $this->data; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Gets the delayed until date/time for the event. |
|
89
|
|
|
* |
|
90
|
|
|
* @return \DateTimeImmutable|null |
|
91
|
|
|
*/ |
|
92
|
|
|
abstract public function delayed_until(): ?DateTimeImmutable; |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Gets the interval between recurring events. |
|
96
|
|
|
* |
|
97
|
|
|
* @return int|null |
|
98
|
|
|
*/ |
|
99
|
|
|
final public function interval(): ?int { |
|
100
|
|
|
return null; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Is the event unique? |
|
105
|
|
|
* |
|
106
|
|
|
* @return bool |
|
107
|
|
|
*/ |
|
108
|
|
|
final public function is_unique(): bool { |
|
109
|
|
|
return $this->is_unique; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|