forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatchEvent.php
More file actions
73 lines (65 loc) · 2.4 KB
/
CatchEvent.php
File metadata and controls
73 lines (65 loc) · 2.4 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
<?php
namespace ProcessMaker\Jobs;
use ProcessMaker\Models\Process as Definitions;
use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface;
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface;
use ProcessMaker\Nayra\Contracts\Bpmn\MessageEventDefinitionInterface;
use ProcessMaker\Nayra\Contracts\Bpmn\DataStoreInterface;
class CatchEvent extends BpmnAction
{
public $definitionsId;
public $processId;
public $elementId;
public $data;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Definitions $definitions, ExecutionInstanceInterface $instance, TokenInterface $token, array $data)
{
$this->definitionsId = $definitions->getKey();
$this->instanceId = $instance->getKey();
$this->tokenId = $token->getKey();
$this->data = $data;
}
/**
* Start a $process from catch event $element.
*
* @param TokenInterface $token
* @param CatchEventInterface $element
* @return \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface
*/
public function action(TokenInterface $token, CatchEventInterface $element)
{
$dataStore = $token->getInstance()->getDataStore();
$element->execute($element->getEventDefinitions()->item(0), $token->getInstance());
foreach ($element->getEventDefinitions() as $eventDefinition) {
if ($eventDefinition instanceof MessageEventDefinitionInterface) {
$this->messageEventUpdateData($eventDefinition, $dataStore);
}
}
}
/**
* Updata data for a message event
*
* If variableName is set, then the event payload will be set to that variable name.
* If the data name exists, then the data is merged.
*
* @param DataStoreInterface $dataStore
* @return void
*/
private function messageEventUpdateData(MessageEventDefinitionInterface $eventDefinition, DataStoreInterface $dataStore)
{
$variableName = $eventDefinition->getProperty('variableName');
$variableName = $variableName === 'undefined' ? '' : $variableName;
if ($variableName) {
$dataStore->putData($variableName, $this->data);
} else {
foreach ($this->data as $key => $value) {
$dataStore->putData($key, $value);
}
}
}
}