ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilBPMN2Parser.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
20  public function parseBPMN2XML($bpmn2_xml, $workflow_name = null)
21  {
22  $bpmn2_array = $this->convertXmlToArray( $bpmn2_xml );
23  $process = $this->getProcessNodeFromArray( $bpmn2_array );
24  $messages = $this->getMessageNodesFromArray( $bpmn2_array );
25 
26  $workflow_name = $this->determineWorkflowClassName( $workflow_name, $bpmn2_array, $process );
27 
28  require_once './Services/WorkflowEngine/classes/parser/class.ilWorkflowScaffold.php';
29  $class_object = new ilWorkflowScaffold($bpmn2_array);
30 
31  $constructor_method_content = '';
32 
33  $class_object->setWorkflowName($workflow_name);
34 
35  if(count(@$process['children']))
36  {
37  $stashed_sequence_flows = array(); // There can be no assumption, that the workflow is modeled in sequence,
38  // so we need to stash the connectors to add them after the nodes.
39  $stashed_associations = array(); // There can be no assumption, that the workflow is modeled in sequence,
40  // so we need to stash the connectors to add them after the nodes.
41  $stashed_process_extensions = array(); // It was found that modelers add extensions at process level,
42  // they are stored for possible future use.
43  require_once './Services/WorkflowEngine/classes/parser/elements/class.ilBPMN2ElementLoader.php';
44 
45  $loader = new ilBPMN2ElementLoader($bpmn2_array);
46 
47  foreach($process['children'] as $element)
48  {
49  if($element['name'] == 'ioSpecification')
50  {
51  foreach($element['children'] as $iospec_element)
52  {
53  $element_object = $loader->load($iospec_element['name']);
54  $constructor_method_content .= $element_object->getPHP($iospec_element, $class_object);
55  }
56 
57  continue;
58  }
59 
60  if($element['name'] == 'sequenceFlow')
61  {
62  $stashed_sequence_flows[] = $element;
63  }
64  else if($element['name'] == 'association')
65  {
66  $stashed_associations[] = $element;
67  }
68  else if($element['name'] == 'extensionElements')
69  {
70  $stashed_process_extensions[] = $element;
71  }
72  else
73  {
74  $element_object = $loader->load($element['name']);
75  $constructor_method_content .= $element_object->getPHP($element, $class_object);
76  }
77  }
78 
79  foreach($stashed_sequence_flows as $element)
80  {
81  $element_object = $loader->load($element['name']);
82  $constructor_method_content .= $element_object->getPHP($element, $class_object);
83  }
84 
85  foreach($stashed_associations as $element)
86  {
87  $element_object = $loader->load($element['name']);
88  $constructor_method_content .= $element_object->getPHP($element, $class_object);
89  }
90  }
91 
92  if(count($messages))
93  {
94  $message_definitions = array();
95  foreach ($messages as $message)
96  {
97  $element_object = $loader->load('messageDefinition');
98  $message_definitions[] = $element_object->getMessageDefinitionArray($message);
99  }
100 
101  $code = '
102  public static function getMessageDefinition($id)
103  {
104  $definitions = array('.implode(',', $message_definitions).'
105  );
106  return $definitions[$id];
107  }
108  ';
109  $class_object->addAuxilliaryMethod($code);
110  }
111 
112  $class_object->setConstructorMethodContent($constructor_method_content);
113  $class_source = '';
114 
115  if (strlen($constructor_method_content))
116  {
117  $class_source .= $class_object->getPHP();
118  }
119 
120  return "<?php\n" . $class_source . "\n?>"; // PHP Code
121  }
122 
128  public function convertXmlToArray($xml)
129  {
130  require_once './Services/WorkflowEngine/classes/parser/class.ilBPMN2ParserUtils.php';
131  $xml_to_array_parser = new ilBPMN2ParserUtils();
132  $bpmn2 = $xml_to_array_parser->load_string( $xml );
133  return $bpmn2;
134  }
135 
141  public function getProcessNodeFromArray($bpmn2)
142  {
143  $process = array();
144  foreach ((array)@$bpmn2['children'] as $bpmn2_part)
145  {
146  if ($bpmn2_part['name'] == 'process')
147  {
148  $process = $bpmn2_part;
149  break;
150  }
151  }
152  return $process;
153  }
154 
160  public function getMessageNodesFromArray($bpmn2)
161  {
162  $messages = array();
163  foreach ((array)@$bpmn2['children'] as $bpmn2_part)
164  {
165  if ($bpmn2_part['name'] == 'message')
166  {
167  $messages[] = $bpmn2_part;
168  break;
169  }
170  }
171  return $messages;
172  }
173 
181  public function determineWorkflowClassName($workflow_name, $bpmn2_array, $process)
182  {
183  if (!$workflow_name && !count( @$bpmn2_array['children'] ))
184  {
185  $workflow_name = $bpmn2_array['attributes']['id'];
186  }
187 
188  if (!$workflow_name)
189  {
190  $workflow_name = $process['attributes']['id'];
191  return $workflow_name;
192  }
193 
194  if ($workflow_name)
195  {
196  $workflow_name = substr($workflow_name,0,strpos($workflow_name,'.'));
197  }
198  return $workflow_name;
199  }
200 }
Class ilBPMN2ElementLoader.
Class ilWorkflowScaffold.
$code
Definition: example_050.php:99
getMessageNodesFromArray($bpmn2)
determineWorkflowClassName($workflow_name, $bpmn2_array, $process)
Class ilBPMN2ParserUtils.
getProcessNodeFromArray($bpmn2)
Create styles array
The data for the language used.
parseBPMN2XML($bpmn2_xml, $workflow_name=null)
$messages
Definition: en-x-test.php:7
Class ilBPMN2Parser.