|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Resta\Schedule; |
|
4
|
|
|
|
|
5
|
|
|
class ScheduleManager implements ScheduleInterface |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var array |
|
9
|
|
|
*/ |
|
10
|
|
|
protected static $cronScheduler = ['*','*','*','*','*']; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* schedule daily |
|
14
|
|
|
* |
|
15
|
|
|
* @param int $hour |
|
16
|
|
|
* @param int $minute |
|
17
|
|
|
* @return void |
|
18
|
|
|
*/ |
|
19
|
|
|
public function daily($hour=0,$minute=0) |
|
20
|
|
|
{ |
|
21
|
|
|
self::$cronScheduler[1] = $hour; |
|
22
|
|
|
|
|
23
|
|
|
self::$cronScheduler[0] = $minute; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* set day for scheduler |
|
28
|
|
|
* |
|
29
|
|
|
* @param integer $day |
|
30
|
|
|
* @return $this |
|
31
|
|
|
*/ |
|
32
|
|
|
public function day($day = 1) |
|
33
|
|
|
{ |
|
34
|
|
|
self::$cronScheduler[2] = $day; |
|
35
|
|
|
|
|
36
|
|
|
return $this; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* set everyHour for scheduler |
|
41
|
|
|
* |
|
42
|
|
|
* @param integer $hour |
|
43
|
|
|
* @return $this |
|
44
|
|
|
*/ |
|
45
|
|
|
public function everyHour($hour = 1) |
|
46
|
|
|
{ |
|
47
|
|
|
self::$cronScheduler[0] = '*'; |
|
48
|
|
|
self::$cronScheduler[1] = '*/'.$hour; |
|
49
|
|
|
|
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* set everyMinute for scheduler |
|
55
|
|
|
* |
|
56
|
|
|
* @param int $minute |
|
57
|
|
|
* @return $this |
|
58
|
|
|
*/ |
|
59
|
|
|
public function everyMinute($minute = 1) |
|
60
|
|
|
{ |
|
61
|
|
|
self::$cronScheduler[0] = '*/'.$minute.''; |
|
62
|
|
|
|
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* get cron scheduler |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getCronScheduler() |
|
72
|
|
|
{ |
|
73
|
|
|
return self::$cronScheduler; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* set hour for scheduler |
|
78
|
|
|
* |
|
79
|
|
|
* @param mixed $hour |
|
80
|
|
|
* @return $this |
|
81
|
|
|
*/ |
|
82
|
|
|
public function hour($hour = '*') |
|
83
|
|
|
{ |
|
84
|
|
|
self::$cronScheduler[1] = $hour; |
|
85
|
|
|
|
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* set minute for scheduler |
|
91
|
|
|
* |
|
92
|
|
|
* @param int $minute |
|
93
|
|
|
* @return $this |
|
94
|
|
|
*/ |
|
95
|
|
|
public function minute($minute = 1) |
|
96
|
|
|
{ |
|
97
|
|
|
self::$cronScheduler[0] = $minute; |
|
98
|
|
|
|
|
99
|
|
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* set month for scheduler |
|
104
|
|
|
* |
|
105
|
|
|
* @param mixed $month |
|
106
|
|
|
* @return $this |
|
107
|
|
|
*/ |
|
108
|
|
|
public function month($month = 1) |
|
109
|
|
|
{ |
|
110
|
|
|
self::$cronScheduler[3] = $month; |
|
111
|
|
|
|
|
112
|
|
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* set month for scheduler |
|
117
|
|
|
* |
|
118
|
|
|
* @param mixed $month |
|
119
|
|
|
* @return $this |
|
120
|
|
|
*/ |
|
121
|
|
|
public function week($week = 1) |
|
122
|
|
|
{ |
|
123
|
|
|
self::$cronScheduler[4] = $week; |
|
124
|
|
|
|
|
125
|
|
|
return $this; |
|
126
|
|
|
} |
|
127
|
|
|
} |