-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventDispatchJob.php
More file actions
96 lines (85 loc) · 2.27 KB
/
EventDispatchJob.php
File metadata and controls
96 lines (85 loc) · 2.27 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Arikaim
*
* @link http://www.arikaim.com
* @copyright Copyright (c) Konstantin Atanasov <info@arikaim.com>
* @license http://www.arikaim.com/license
*
*/
namespace Arikaim\Core\Events;
use Arikaim\Core\Interfaces\Job\JobInterface;
use Arikaim\Core\Queue\Jobs\Job;
/**
* Event dispatch job
*/
class EventDispatchJob extends Job implements JobInterface
{
/**
* Event manager ref
*
* @var object
*/
protected $eventManager;
/**
* Constructor
*
* @param array $params
* @param object $eventManager
*/
public function __construct(array $params, object &$eventManager)
{
parent::__construct(null,$params);
$this->eventManager = $eventManager;
}
/**
* Init job
*
* @return void
*/
public function init(): void
{
$this->setName('event.dispatch');
}
/**
* Job code
*
* @return mixed
*/
public function execute()
{
$eventName = $this->getParam('event_name');
$eventParams = $this->getParam('event_name',[]);
if (empty($eventName) == true) {
return false;
}
$this->eventManager->dispatch($eventName,$eventParams);
}
/**
* Init descriptor properties
*
* @return void
*/
protected function initDescriptor(): void
{
$this->descriptor->set('title','Event dispatch');
$this->descriptor->set('description','Event dispatch job.');
$this->descriptor->set('allow.admin.config',false);
$this->descriptor->set('allow.console.push',true);
// properties
$this->descriptor->collection('parameters')->property('event_name',function($property) {
$property
->title('Event Name')
->type('text')
->required(true)
->value('');
});
$this->descriptor->collection('parameters')->property('event_params',function($property) {
$property
->title('Event Params')
->type('list')
->required(false)
->value(null);
});
}
}