1 | <?php |
||||
2 | |||||
3 | namespace yii2mod\scheduling; |
||||
4 | |||||
5 | use yii\base\Application; |
||||
6 | use yii\base\InvalidParamException; |
||||
7 | |||||
8 | /** |
||||
9 | * Class CallbackEvent |
||||
10 | * |
||||
11 | * @package yii2mod\scheduling |
||||
12 | */ |
||||
13 | class CallbackEvent extends Event |
||||
14 | { |
||||
15 | /** |
||||
16 | * The callback to call. |
||||
17 | * |
||||
18 | * @var string |
||||
19 | */ |
||||
20 | protected $callback; |
||||
21 | |||||
22 | /** |
||||
23 | * The parameters to pass to the method. |
||||
24 | * |
||||
25 | * @var array |
||||
26 | */ |
||||
27 | protected $parameters; |
||||
28 | |||||
29 | /** |
||||
30 | * @param string $callback |
||||
31 | * @param array $parameters |
||||
32 | * @param array $config |
||||
33 | */ |
||||
34 | public function __construct($callback, array $parameters = [], $config = []) |
||||
35 | { |
||||
36 | $this->callback = $callback; |
||||
37 | $this->parameters = $parameters; |
||||
38 | |||||
39 | if (!is_string($this->callback) && !is_callable($this->callback)) { |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
40 | throw new InvalidParamException( |
||||
0 ignored issues
–
show
The class
yii\base\InvalidParamException has been deprecated: since 2.0.14. Use [[InvalidArgumentException]] instead.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
41 | 'Invalid scheduled callback event. Must be string or callable.' |
||||
42 | ); |
||||
43 | } |
||||
44 | |||||
45 | parent::__construct($config); |
||||
0 ignored issues
–
show
$config of type array is incompatible with the type string expected by parameter $command of yii2mod\scheduling\Event::__construct() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
46 | } |
||||
47 | |||||
48 | /** |
||||
49 | * Run the given event. |
||||
50 | * |
||||
51 | * @param Application $app |
||||
52 | * |
||||
53 | * @return mixed |
||||
54 | */ |
||||
55 | public function run(Application $app) |
||||
56 | { |
||||
57 | $response = call_user_func_array($this->callback, array_merge($this->parameters, [$app])); |
||||
58 | parent::callAfterCallbacks($app); |
||||
59 | |||||
60 | return $response; |
||||
61 | } |
||||
62 | |||||
63 | /** |
||||
64 | * Get the summary of the event for display. |
||||
65 | * |
||||
66 | * @return string |
||||
67 | */ |
||||
68 | public function getSummaryForDisplay() |
||||
69 | { |
||||
70 | if (is_string($this->_description)) { |
||||
0 ignored issues
–
show
|
|||||
71 | return $this->_description; |
||||
72 | } |
||||
73 | |||||
74 | return is_string($this->callback) ? $this->callback : 'Closure'; |
||||
75 | } |
||||
76 | } |
||||
77 |