|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Jitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) Jitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Jitamin\Bus\Job; |
|
13
|
|
|
|
|
14
|
|
|
use Jitamin\Bus\Event\TaskEvent; |
|
15
|
|
|
use Jitamin\Bus\EventBuilder\TaskEventBuilder; |
|
16
|
|
|
use Jitamin\Model\TaskModel; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class TaskEventJob. |
|
20
|
|
|
*/ |
|
21
|
|
|
class TaskEventJob extends BaseJob |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Set job params. |
|
25
|
|
|
* |
|
26
|
|
|
* @param int $taskId |
|
27
|
|
|
* @param array $eventNames |
|
28
|
|
|
* @param array $changes |
|
29
|
|
|
* @param array $values |
|
30
|
|
|
* @param array $task |
|
31
|
|
|
* |
|
32
|
|
|
* @return $this |
|
33
|
|
|
*/ |
|
34
|
|
|
public function withParams($taskId, array $eventNames, array $changes = [], array $values = [], array $task = []) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->jobParams = [$taskId, $eventNames, $changes, $values, $task]; |
|
37
|
|
|
|
|
38
|
|
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Execute job. |
|
43
|
|
|
* |
|
44
|
|
|
* @param int $taskId |
|
45
|
|
|
* @param array $eventNames |
|
46
|
|
|
* @param array $changes |
|
47
|
|
|
* @param array $values |
|
48
|
|
|
* @param array $task |
|
49
|
|
|
* |
|
50
|
|
|
* @return $this |
|
51
|
|
|
*/ |
|
52
|
|
|
public function execute($taskId, array $eventNames, array $changes = [], array $values = [], array $task = []) |
|
53
|
|
|
{ |
|
54
|
|
|
$event = TaskEventBuilder::getInstance($this->container) |
|
55
|
|
|
->withTaskId($taskId) |
|
56
|
|
|
->withChanges($changes) |
|
57
|
|
|
->withValues($values) |
|
58
|
|
|
->withTask($task) |
|
59
|
|
|
->buildEvent(); |
|
60
|
|
|
|
|
61
|
|
|
if ($event !== null) { |
|
62
|
|
|
foreach ($eventNames as $eventName) { |
|
63
|
|
|
$this->fireEvent($eventName, $event); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Trigger event. |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $eventName |
|
72
|
|
|
* @param TaskEvent $event |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function fireEvent($eventName, TaskEvent $event) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->logger->debug(__METHOD__.' Event fired: '.$eventName); |
|
|
|
|
|
|
77
|
|
|
$this->dispatcher->dispatch($eventName, $event); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
if ($eventName === TaskModel::EVENT_CREATE) { |
|
80
|
|
|
$this->userMentionModel->fireEvents($event['task']['description'], TaskModel::EVENT_USER_MENTION, $event); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.