1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Basebuilder\Scheduling; |
4
|
|
|
|
5
|
|
|
use Cron\CronExpression; |
6
|
|
|
|
7
|
|
|
interface Event |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @return string|null |
11
|
|
|
*/ |
12
|
|
|
public function getName(); |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @return string |
16
|
|
|
*/ |
17
|
|
|
public function __toString(); |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param string $description |
21
|
|
|
* @return $this |
22
|
|
|
*/ |
23
|
|
|
public function describe($description); |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Set a name for the event. Used to just run this event with the scheduler |
27
|
|
|
* |
28
|
|
|
* @param string $name |
29
|
|
|
* @return $this |
30
|
|
|
*/ |
31
|
|
|
public function name($name); |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Run the given event. |
35
|
|
|
* |
36
|
|
|
* @return mixed |
37
|
|
|
*/ |
38
|
|
|
public function run(); |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Schedule the event to run between start and end time. |
42
|
|
|
* |
43
|
|
|
* @param string $startTime |
44
|
|
|
* @param string $endTime |
45
|
|
|
* @return $this |
46
|
|
|
*/ |
47
|
|
|
public function between($startTime, $endTime); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Schedule the event to not run between start and end time. |
51
|
|
|
* |
52
|
|
|
* @param string $startTime |
53
|
|
|
* @param string $endTime |
54
|
|
|
* @return $this |
55
|
|
|
*/ |
56
|
|
|
public function notBetween($startTime, $endTime); |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Set the timezone the date should be evaluated on. |
60
|
|
|
* |
61
|
|
|
* @return $this |
62
|
|
|
*/ |
63
|
|
|
public function timezone(\DateTimeZone $timezone); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Determine if the given event should run based on the Cron expression. |
67
|
|
|
* |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
|
|
public function isDue(); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* The Cron expression representing the event's frequency. |
74
|
|
|
* |
75
|
|
|
* @param string $expression |
76
|
|
|
* @return $this |
77
|
|
|
*/ |
78
|
|
|
public function cron(/* string */ $expression); |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return CronExpression |
82
|
|
|
*/ |
83
|
|
|
public function getCronExpression(); |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Change the minute when the job should run (0-59, *, *\/2 etc) |
87
|
|
|
* |
88
|
|
|
* @param string|int $minute |
89
|
|
|
* @return $this |
90
|
|
|
*/ |
91
|
|
|
public function minute($minute); |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Schedule the event to run every minute. |
95
|
|
|
* |
96
|
|
|
* @return $this |
97
|
|
|
*/ |
98
|
|
|
public function everyMinute(); |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Schedule this event to run every 5 minutes |
102
|
|
|
* |
103
|
|
|
* @return Event |
104
|
|
|
*/ |
105
|
|
|
public function everyFiveMinutes(); |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Schedule the event to run every N minutes |
109
|
|
|
* |
110
|
|
|
* @param int $n |
111
|
|
|
* @return $this |
112
|
|
|
*/ |
113
|
|
|
public function everyNMinutes(/* int */ $n); |
|
|
|
|
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Set the hour when the job should run (0-23, *, *\/2, etc) |
117
|
|
|
* |
118
|
|
|
* @param string|int $hour |
119
|
|
|
* @return Event |
120
|
|
|
*/ |
121
|
|
|
public function hour($hour); |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Schedule the event to run hourly. |
125
|
|
|
* |
126
|
|
|
* @return $this |
127
|
|
|
*/ |
128
|
|
|
public function hourly(); |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Schedule the event to run daily. |
132
|
|
|
* |
133
|
|
|
* @return $this |
134
|
|
|
*/ |
135
|
|
|
public function daily(); |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Schedule the event to run daily at a given time (10:00, 19:30, etc). |
139
|
|
|
* |
140
|
|
|
* @param string $time |
141
|
|
|
* @return $this |
142
|
|
|
*/ |
143
|
|
|
public function dailyAt(/* string */ $time); |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Set the days of the week the command should run on. |
147
|
|
|
* |
148
|
|
|
* @param array|mixed $days |
149
|
|
|
* @return $this |
150
|
|
|
*/ |
151
|
|
|
public function days($days); |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Schedule the event to run only on weekdays. |
155
|
|
|
* |
156
|
|
|
* @return $this |
157
|
|
|
*/ |
158
|
|
|
public function weekdays(); |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Schedule the event to run only on Mondays. |
162
|
|
|
* |
163
|
|
|
* @return $this |
164
|
|
|
*/ |
165
|
|
|
public function mondays(); |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Schedule the event to run only on Tuesdays. |
169
|
|
|
* |
170
|
|
|
* @return $this |
171
|
|
|
*/ |
172
|
|
|
public function tuesdays(); |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Schedule the event to run only on Wednesdays. |
176
|
|
|
* |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
|
|
public function wednesdays(); |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Schedule the event to run only on Thursdays. |
183
|
|
|
* |
184
|
|
|
* @return $this |
185
|
|
|
*/ |
186
|
|
|
public function thursdays(); |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Schedule the event to run only on Fridays. |
190
|
|
|
* |
191
|
|
|
* @return $this |
192
|
|
|
*/ |
193
|
|
|
public function fridays(); |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Schedule the event to run only on Saturdays. |
197
|
|
|
* |
198
|
|
|
* @return $this |
199
|
|
|
*/ |
200
|
|
|
public function saturdays(); |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Schedule the event to run only on Sundays. |
204
|
|
|
* |
205
|
|
|
* @return $this |
206
|
|
|
*/ |
207
|
|
|
public function sundays(); |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Schedule the event to run weekly. |
211
|
|
|
* |
212
|
|
|
* @return $this |
213
|
|
|
*/ |
214
|
|
|
public function weekly(); |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Schedule the event to run weekly on a given day and time. |
218
|
|
|
* |
219
|
|
|
* @param int $day |
220
|
|
|
* @param string $time |
221
|
|
|
* @return $this |
222
|
|
|
*/ |
223
|
|
|
public function weeklyOn($day, $time = '0:0'); |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Schedule the event to run monthly. |
227
|
|
|
* |
228
|
|
|
* @return $this |
229
|
|
|
*/ |
230
|
|
|
public function monthly(); |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Schedule the event to run monthly on a given day and time. |
234
|
|
|
* |
235
|
|
|
* @param int $day |
236
|
|
|
* @param string $time |
237
|
|
|
* @return $this |
238
|
|
|
*/ |
239
|
|
|
public function monthlyOn($day = 1, $time = '0:0'); |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Schedule the event to run quarterly. |
243
|
|
|
* |
244
|
|
|
* @return $this |
245
|
|
|
*/ |
246
|
|
|
public function quarterly(); |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Schedule the event to run yearly. |
250
|
|
|
* |
251
|
|
|
* @return $this |
252
|
|
|
*/ |
253
|
|
|
public function yearly(); |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Register a callback to further filter the schedule. |
257
|
|
|
* |
258
|
|
|
* @param callable $callback |
259
|
|
|
* @return $this |
260
|
|
|
*/ |
261
|
|
|
public function when(callable $callback); |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Register a callback to further filter the schedule. |
265
|
|
|
* |
266
|
|
|
* @param callable $callback |
267
|
|
|
* @return $this |
268
|
|
|
*/ |
269
|
|
|
public function skip(callable $callback); |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Register a callback to be called before the operation. |
273
|
|
|
* |
274
|
|
|
* @param callable $callback |
275
|
|
|
* @return $this |
276
|
|
|
*/ |
277
|
|
|
public function before(callable $callback); |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Register a callback to be called after the operation. |
281
|
|
|
* |
282
|
|
|
* @param callable $callback |
283
|
|
|
* @return $this |
284
|
|
|
*/ |
285
|
|
|
public function after(callable $callback); |
286
|
|
|
} |
287
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.