-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathMessage.php
More file actions
70 lines (59 loc) · 1.56 KB
/
Message.php
File metadata and controls
70 lines (59 loc) · 1.56 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
<?php
namespace ProcessMaker\Models;
use ProcessMaker\Nayra\Bpmn\Models\Message as MessageBase;
/**
* Implementation of the message element.
*/
class Message extends MessageBase
{
const PAYLOAD_EXPRESSION = '/^\{([\w.,\s]+)\}$/';
const MAP_EXPRESSION = '/^\s*(\w+)\s*:\s*([\w.]+)\s*$/';
const ITEM_EXPRESSION = '/^\s*(\w+)\s*$/';
/**
* @var mixed
*/
private $payload;
/**
* Get the payload of the message.
*
* @return mixed
*/
public function getPayload()
{
return $this->payload;
}
/**
* Get the payload of the message.
*
* @param mixed $payload
*
* @return $this
*/
public function setPayload($payload)
{
$this->payload = $payload;
return $this;
}
/**
* Get the serializable content of message
*/
public function getData(ProcessRequest $instance)
{
$source = $instance->data;
$data = [];
if (preg_match(self::PAYLOAD_EXPRESSION, $this->getPayload(), $match)) {
$elements = explode(',', $match[1]);
foreach ($elements as $element) {
if (preg_match(self::MAP_EXPRESSION, $element, $map)) {
$name = $map[1];
$reference = $map[2];
} elseif (preg_match(self::ITEM_EXPRESSION, $element, $map)) {
$name = $map[1];
$reference = $map[1];
}
$data[$name] = array_get($source, $reference);
}
}
return $data;
}
}