1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of php-task library. |
5
|
|
|
* |
6
|
|
|
* (c) php-task |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Task\Builder; |
13
|
|
|
|
14
|
|
|
use Cron\CronExpression; |
15
|
|
|
use Task\TaskInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Builder for tasks. |
19
|
|
|
*/ |
20
|
|
|
class TaskBuilder implements TaskBuilderInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var TaskInterface |
24
|
|
|
*/ |
25
|
|
|
private $task; |
26
|
|
|
|
27
|
9 |
|
public function __construct(TaskInterface $task) |
28
|
|
|
{ |
29
|
9 |
|
$this->task = $task; |
30
|
9 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
1 |
|
public function hourly(\DateTime $firstExecution = null, \DateTime $lastExecution = null) |
36
|
|
|
{ |
37
|
1 |
|
$this->task->setInterval(CronExpression::factory('@hourly'), $firstExecution, $lastExecution); |
38
|
|
|
|
39
|
1 |
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
1 |
|
public function daily(\DateTime $firstExecution = null, \DateTime $lastExecution = null) |
46
|
|
|
{ |
47
|
1 |
|
$this->task->setInterval(CronExpression::factory('@daily'), $firstExecution, $lastExecution); |
48
|
|
|
|
49
|
1 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
1 |
|
public function weekly(\DateTime $firstExecution = null, \DateTime $lastExecution = null) |
56
|
|
|
{ |
57
|
1 |
|
$this->task->setInterval(CronExpression::factory('@weekly'), $firstExecution, $lastExecution); |
58
|
|
|
|
59
|
1 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
1 |
|
public function monthly(\DateTime $firstExecution = null, \DateTime $lastExecution = null) |
66
|
|
|
{ |
67
|
1 |
|
$this->task->setInterval(CronExpression::factory('@monthly'), $firstExecution, $lastExecution); |
68
|
|
|
|
69
|
1 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
2 |
|
public function yearly(\DateTime $firstExecution = null, \DateTime $lastExecution = null) |
76
|
|
|
{ |
77
|
2 |
|
$this->task->setInterval(CronExpression::factory('@yearly'), $firstExecution, $lastExecution); |
78
|
|
|
|
79
|
1 |
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritdoc} |
84
|
|
|
*/ |
85
|
1 |
|
public function cron($cronExpression, \DateTime $firstExecution = null, \DateTime $lastExecution = null) |
86
|
|
|
{ |
87
|
1 |
|
$this->task->setInterval(CronExpression::factory($cronExpression), $firstExecution, $lastExecution); |
88
|
|
|
|
89
|
1 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
1 |
|
public function executeAt(\DateTime $executionDate) |
96
|
|
|
{ |
97
|
1 |
|
$this->task->setFirstExecution($executionDate); |
98
|
|
|
|
99
|
1 |
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
1 |
|
public function getTask() |
106
|
|
|
{ |
107
|
1 |
|
return $this->task; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|