|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Impl\Event; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Impl\Bpmn\Behavior\EventSubProcessStartEventActivityBehavior; |
|
6
|
|
|
use Jabe\Impl\Interceptor\CommandContext; |
|
7
|
|
|
use Jabe\Impl\Persistence\Entity\EventSubscriptionEntity; |
|
8
|
|
|
use Jabe\Impl\Util\EnsureUtil; |
|
9
|
|
|
|
|
10
|
|
|
class EventHandlerImpl implements EventHandlerInterface |
|
11
|
|
|
{ |
|
12
|
|
|
private $eventType; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct(EventType $eventType) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->eventType = $eventType; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function handleIntermediateEvent( |
|
20
|
|
|
EventSubscriptionEntity $eventSubscription, |
|
21
|
|
|
$payload, |
|
22
|
|
|
$localPayload, |
|
23
|
|
|
CommandContext $commandContext |
|
|
|
|
|
|
24
|
|
|
): void { |
|
25
|
|
|
$execution = $eventSubscription->getExecution(); |
|
26
|
|
|
$activity = $eventSubscription->getActivity(); |
|
27
|
|
|
|
|
28
|
|
|
EnsureUtil::ensureNotNull( |
|
29
|
|
|
"Error while sending signal for event subscription '" . $eventSubscription->getId() . "': " |
|
30
|
|
|
. "no activity associated with event subscription", |
|
31
|
|
|
"activity", |
|
32
|
|
|
$activity |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
if (is_array($payload) && !empty($payload)) { |
|
36
|
|
|
$execution->setVariables($payload); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
if (is_array($localPayload) && !empty($localPayload)) { |
|
40
|
|
|
$execution->setVariablesLocal($localPayload); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if ($activity == $execution->getActivity()) { |
|
44
|
|
|
$execution->signal("signal", null); |
|
45
|
|
|
} else { |
|
46
|
|
|
// hack around the fact that the start event is referenced by event subscriptions for event subprocesses |
|
47
|
|
|
// and not the subprocess itself |
|
48
|
|
|
if ($activity->getActivityBehavior() instanceof EventSubProcessStartEventActivityBehavior) { |
|
49
|
|
|
$activity = $activity->getFlowScope(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$execution->executeEventHandlerActivity($activity); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function handleEvent( |
|
57
|
|
|
EventSubscriptionEntity $eventSubscription, |
|
58
|
|
|
$payload, |
|
59
|
|
|
$localPayload, |
|
60
|
|
|
?string $businessKey, |
|
61
|
|
|
CommandContext $commandContext |
|
62
|
|
|
): void { |
|
63
|
|
|
$this->handleIntermediateEvent($eventSubscription, $payload, $localPayload, $commandContext); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getEventHandlerType(): string |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->eventType->name(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.