forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessTrait.php
More file actions
61 lines (56 loc) · 1.88 KB
/
ProcessTrait.php
File metadata and controls
61 lines (56 loc) · 1.88 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
<?php
namespace ProcessMaker\Traits;
use ProcessMaker\Models\ProcessVersion;
use ProcessMaker\Nayra\Contracts\Storage\BpmnDocumentInterface;
use ProcessMaker\Nayra\Exceptions\ElementNotFoundException;
use ProcessMaker\Repositories\BpmnDocument;
trait ProcessTrait
{
/**
* Parsed process BPMN definitions.
*
* @var \ProcessMaker\Nayra\Contracts\Storage\BpmnDocumentInterface
*/
private $bpmnDefinitions;
/**
* Get the process definitions from BPMN field.
*
* @param bool $forceParse
*
* @return BpmnDocument
*/
public function getDefinitions($forceParse = false, $engine = null, $globalEvents = true)
{
if ($forceParse || empty($this->bpmnDefinitions)) {
$options = ['process' => $this instanceof ProcessVersion ? $this->process : $this];
!$engine ?: $options['engine'] = $engine;
$options['globalEvents'] = $globalEvents;
$this->bpmnDefinitions = app(BpmnDocumentInterface::class, $options);
if ($this->bpmn) {
$this->bpmnDefinitions->loadXML($this->bpmn);
try {
$this->bpmnDefinitions->getEngine()->loadProcessDefinitions($this->bpmnDefinitions);
} catch (ElementNotFoundException $e) {
$warnings = is_array($this->warnings) ? $this->warnings : [];
$warnings[] = [
'title' => __('Element Not Found'),
'text' => $e->getMessage()
];
$this->warnings = $warnings;
}
}
}
return $this->bpmnDefinitions;
}
/**
* Get BPMN DOM Document
*
* @return BpmnDocument
*/
public function getDomDocument()
{
$document = new BpmnDocument($this);
$document->loadXML($this->bpmn);
return $document;
}
}