1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Psr\EnterpriseBeans\Annotations\Schedule |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io-psr/epb |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Psr\EnterpriseBeans\Annotations; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Psr\EnterpriseBeans\ScheduleExpression; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Annotation implementation representing a @Schedule annotation on a bean method. |
27
|
|
|
* |
28
|
|
|
* The annotation can define the following values: |
29
|
|
|
* |
30
|
|
|
* - second |
31
|
|
|
* - minute |
32
|
|
|
* - hour |
33
|
|
|
* - dayOfWeek |
34
|
|
|
* - dayOfMonth |
35
|
|
|
* - month |
36
|
|
|
* - year |
37
|
|
|
* - start |
38
|
|
|
* - end |
39
|
|
|
* - timezone |
40
|
|
|
* |
41
|
|
|
* @author Tim Wagner <[email protected]> |
42
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
43
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
44
|
|
|
* @link https://github.com/appserver-io-psr/epb |
45
|
|
|
* @link http://www.appserver.io |
46
|
|
|
* |
47
|
|
|
* @Annotation |
48
|
|
|
* @Target({"METHOD"}) |
49
|
|
|
*/ |
50
|
|
|
class Schedule extends AbstractAnnotation |
51
|
|
|
{ |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The default number to append to an alias if a number is missing |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
const DEFAULT_NUMBER = '1'; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* The aliases to be replaced with valid CRON values. |
61
|
|
|
* |
62
|
|
|
* @var array |
63
|
|
|
*/ |
64
|
|
|
protected $aliases = array('EVERY' => '*', 'ZERO' => '0', 'SLASH' => '/'); |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* The day of month. |
68
|
|
|
* |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
protected $dayOfMonth; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* The day of week. |
75
|
|
|
* |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
protected $dayOfWeek; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* The end date time. |
82
|
|
|
* |
83
|
|
|
* @var string |
84
|
|
|
*/ |
85
|
|
|
protected $end; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* The the hour. |
89
|
|
|
* |
90
|
|
|
* @var string |
91
|
|
|
*/ |
92
|
|
|
protected $hour; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* The the minute. |
96
|
|
|
* |
97
|
|
|
* @var string |
98
|
|
|
*/ |
99
|
|
|
protected $minute; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* The the month. |
103
|
|
|
* |
104
|
|
|
* @var string |
105
|
|
|
*/ |
106
|
|
|
protected $month; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* The the second. |
110
|
|
|
* |
111
|
|
|
* @var string |
112
|
|
|
*/ |
113
|
|
|
protected $second; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* The start date time. |
117
|
|
|
* |
118
|
|
|
* @var string |
119
|
|
|
*/ |
120
|
|
|
protected $start; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* The the timezone. |
124
|
|
|
* |
125
|
|
|
* @var string |
126
|
|
|
*/ |
127
|
|
|
protected $timezone; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* The the year. |
131
|
|
|
* |
132
|
|
|
* @var string |
133
|
|
|
*/ |
134
|
|
|
protected $year; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* The constructor the initializes the instance with the |
138
|
|
|
* data passed with the token. |
139
|
|
|
* |
140
|
|
|
* @param array $values The annotation values |
141
|
|
|
*/ |
142
|
|
|
public function __construct(array $values = array()) |
143
|
|
|
{ |
144
|
|
|
|
145
|
|
|
// set the values found in the annotation |
146
|
|
|
foreach ($values as $member => $value) { |
147
|
|
|
// check if we've to replace the value |
148
|
|
|
foreach ($this->aliases as $aliasKey => $aliasValue) { |
149
|
|
|
$value = str_replace($aliasKey, $aliasValue, $value); |
150
|
|
|
// Append the default number to the SLASH alias value if no number is given |
151
|
|
|
if ((preg_match('/\/$/', $value)) === 1) { |
152
|
|
|
$value .= self::DEFAULTNUMBER; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
// set the value |
156
|
|
|
$values[$member] = $value; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
// set the day of month attribute, if available |
160
|
|
|
if (isset($values[AnnotationKeys::DAY_OF_MONTH])) { |
161
|
|
|
$this->dayOfMonth = $values[AnnotationKeys::DAY_OF_MONTH]; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
// set the day of week attribute, if available |
165
|
|
|
if (isset($values[AnnotationKeys::DAY_OF_WEEK])) { |
166
|
|
|
$this->dayOfWeek = $values[AnnotationKeys::DAY_OF_WEEK]; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
// set the end attribute, if available |
170
|
|
|
if (isset($values[AnnotationKeys::END])) { |
171
|
|
|
$this->end = $values[AnnotationKeys::END]; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
// set the hour attribute, if available |
175
|
|
|
if (isset($values[AnnotationKeys::HOUR])) { |
176
|
|
|
$this->hour = $values[AnnotationKeys::HOUR]; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
// set the minute attribute, if available |
180
|
|
|
if (isset($values[AnnotationKeys::MINUTE])) { |
181
|
|
|
$this->minute = $values[AnnotationKeys::MINUTE]; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
// set the month attribute, if available |
185
|
|
|
if (isset($values[AnnotationKeys::MONTH])) { |
186
|
|
|
$this->month = $values[AnnotationKeys::MONTH]; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
// set the second attribute, if available |
190
|
|
|
if (isset($values[AnnotationKeys::SECOND])) { |
191
|
|
|
$this->second = $values[AnnotationKeys::SECOND]; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
// set the start attribute, if available |
195
|
|
|
if (isset($values[AnnotationKeys::START])) { |
196
|
|
|
$this->start = $values[AnnotationKeys::START]; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
// set the timezone attribute, if available |
200
|
|
|
if (isset($values[AnnotationKeys::TIMEZONE])) { |
201
|
|
|
$this->timezone = $values[AnnotationKeys::TIMEZONE]; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
// set the year attribute, if available |
205
|
|
|
if (isset($values[AnnotationKeys::YEAR])) { |
206
|
|
|
$this->year = $values[AnnotationKeys::YEAR]; |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Returns day of month. |
212
|
|
|
* |
213
|
|
|
* @return string|null The day of month |
214
|
|
|
*/ |
215
|
|
|
public function getDayOfMonth() |
216
|
|
|
{ |
217
|
|
|
return $this->dayOfMonth; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Returns day of week. |
222
|
|
|
* |
223
|
|
|
* @return string|null The day of week |
224
|
|
|
*/ |
225
|
|
|
public function getDayOfWeek() |
226
|
|
|
{ |
227
|
|
|
return $this->dayOfWeek; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Returns end date time. |
232
|
|
|
* |
233
|
|
|
* @return string|null The last expiration date |
234
|
|
|
*/ |
235
|
|
|
public function getEnd() |
236
|
|
|
{ |
237
|
|
|
return $this->end; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Returns the hour. |
242
|
|
|
* |
243
|
|
|
* @return string|null The hour |
244
|
|
|
*/ |
245
|
|
|
public function getHour() |
246
|
|
|
{ |
247
|
|
|
return $this->hour; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Returns the minute. |
252
|
|
|
* |
253
|
|
|
* @return string|null The minute |
254
|
|
|
*/ |
255
|
|
|
public function getMinute() |
256
|
|
|
{ |
257
|
|
|
return $this->minute; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Returns the month. |
262
|
|
|
* |
263
|
|
|
* @return string|null The month |
264
|
|
|
*/ |
265
|
|
|
public function getMonth() |
266
|
|
|
{ |
267
|
|
|
return $this->month; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Returns the second. |
272
|
|
|
* |
273
|
|
|
* @return string|null The second |
274
|
|
|
*/ |
275
|
|
|
public function getSecond() |
276
|
|
|
{ |
277
|
|
|
return $this->second; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Returns start date time. |
282
|
|
|
* |
283
|
|
|
* @return string|null The initial expiration date |
284
|
|
|
*/ |
285
|
|
|
public function getStart() |
286
|
|
|
{ |
287
|
|
|
return $this->start; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Returns the timezone. |
292
|
|
|
* |
293
|
|
|
* @return null|string The timezone |
294
|
|
|
*/ |
295
|
|
|
public function getTimezone() |
296
|
|
|
{ |
297
|
|
|
return $this->timezone; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Returns the year. |
302
|
|
|
* |
303
|
|
|
* @return string|null The year |
304
|
|
|
*/ |
305
|
|
|
public function getYear() |
306
|
|
|
{ |
307
|
|
|
return $this->year; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Creates a new schedule expression instance from this annotations data. |
312
|
|
|
* |
313
|
|
|
* @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression The expression initialzed with the data from this annotation |
314
|
|
|
*/ |
315
|
|
|
public function toScheduleExpression() |
316
|
|
|
{ |
317
|
|
|
|
318
|
|
|
// create a new expression instance |
319
|
|
|
$expression = new ScheduleExpression(); |
320
|
|
|
|
321
|
|
|
// copy the data from the annotation |
322
|
|
|
$expression->hour($this->getHour()); |
323
|
|
|
$expression->minute($this->getMinute()); |
324
|
|
|
$expression->month($this->getMonth()); |
325
|
|
|
$expression->second($this->getSecond()); |
326
|
|
|
$expression->start($this->getStart()); |
327
|
|
|
$expression->end($this->getEnd()); |
328
|
|
|
$expression->timezone($this->getTimezone()); |
329
|
|
|
$expression->year($this->getYear()); |
330
|
|
|
$expression->dayOfMonth($this->getDayOfMonth()); |
331
|
|
|
$expression->dayOfWeek($this->getDayOfWeek()); |
332
|
|
|
|
333
|
|
|
// return the expression |
334
|
|
|
return $expression; |
335
|
|
|
} |
336
|
|
|
} |
337
|
|
|
|