-
Notifications
You must be signed in to change notification settings - Fork 9
/
CallbackEvent.php
76 lines (65 loc) · 1.57 KB
/
CallbackEvent.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
<?php
namespace yii2mod\scheduling;
use yii\base\Application;
use yii\base\InvalidParamException;
/**
* Class CallbackEvent
*
* @package yii2mod\scheduling
*/
class CallbackEvent extends Event
{
/**
* The callback to call.
*
* @var string
*/
protected $callback;
/**
* The parameters to pass to the method.
*
* @var array
*/
protected $parameters;
/**
* @param string $callback
* @param array $parameters
* @param array $config
*/
public function __construct($callback, array $parameters = [], $config = [])
{
$this->callback = $callback;
$this->parameters = $parameters;
if (!is_string($this->callback) && !is_callable($this->callback)) {
throw new InvalidParamException(
'Invalid scheduled callback event. Must be string or callable.'
);
}
parent::__construct($config);
}
/**
* Run the given event.
*
* @param Application $app
*
* @return mixed
*/
public function run(Application $app)
{
$response = call_user_func_array($this->callback, array_merge($this->parameters, [$app]));
parent::callAfterCallbacks($app);
return $response;
}
/**
* Get the summary of the event for display.
*
* @return string
*/
public function getSummaryForDisplay()
{
if (is_string($this->_description)) {
return $this->_description;
}
return is_string($this->callback) ? $this->callback : 'Closure';
}
}