forked from omnilight/yii2-scheduling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Schedule.php
78 lines (70 loc) · 1.6 KB
/
Schedule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace omnilight\scheduling;
use yii\base\Component;
use yii\base\Application;
/**
* Class Schedule
*/
class Schedule extends Component
{
/**
* All of the events on the schedule.
*
* @var Event[]
*/
protected $_events = [];
/**
* @var string The name of cli script
*/
public $cliScriptName = 'yii';
/**
* Add a new callback event to the schedule.
*
* @param string $callback
* @param array $parameters
* @return Event
*/
public function call($callback, array $parameters = array())
{
$this->_events[] = $event = new CallbackEvent($callback, $parameters);
return $event;
}
/**
* Add a new cli command event to the schedule.
*
* @param string $command
* @return Event
*/
public function command($command)
{
return $this->exec(PHP_BINARY . ' ' . $this->cliScriptName . ' ' . $command);
}
/**
* Add a new command event to the schedule.
*
* @param string $command
* @return Event
*/
public function exec($command)
{
$this->_events[] = $event = new Event($command);
return $event;
}
public function getEvents()
{
return $this->_events;
}
/**
* Get all of the events on the schedule that are due.
*
* @param \yii\base\Application $app
* @return Event[]
*/
public function dueEvents(Application $app)
{
return array_filter($this->_events, function(Event $event) use ($app)
{
return $event->isDue($app);
});
}
}