|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Engine\Impl\Json; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Engine\Impl\Cmd\{ |
|
6
|
|
|
AbstractProcessInstanceModificationCommand, |
|
7
|
|
|
ActivityAfterInstantiationCmd, |
|
8
|
|
|
ActivityBeforeInstantiationCmd, |
|
9
|
|
|
ActivityCancellationCmd, |
|
10
|
|
|
ActivityInstanceCancellationCmd, |
|
11
|
|
|
TransitionInstanceCancellationCmd, |
|
12
|
|
|
TransitionInstantiationCmd |
|
13
|
|
|
}; |
|
14
|
|
|
use Jabe\Engine\Impl\Util\JsonUtil; |
|
15
|
|
|
|
|
16
|
|
|
class ModificationCmdJsonConverter extends JsonObjectConverter |
|
17
|
|
|
{ |
|
18
|
|
|
private static $INSTANCE; |
|
19
|
|
|
public const START_BEFORE = "startBeforeActivity"; |
|
20
|
|
|
public const START_AFTER = "startAfterActivity"; |
|
21
|
|
|
public const START_TRANSITION = "startTransition"; |
|
22
|
|
|
public const CANCEL_ALL = "cancelAllForActivity"; |
|
23
|
|
|
public const CANCEL_CURRENT = "cancelCurrentActiveActivityInstances"; |
|
24
|
|
|
public const CANCEL_ACTIVITY_INSTANCES = "cancelActivityInstances"; |
|
25
|
|
|
public const PROCESS_INSTANCE = "processInstances"; |
|
26
|
|
|
public const CANCEL_TRANSITION_INSTANCES = "cancelTransitionInstances"; |
|
27
|
|
|
|
|
28
|
|
|
public static function instance(): ModificationCmdJsonConverter |
|
29
|
|
|
{ |
|
30
|
|
|
if (self::$INSTANCE == null) { |
|
31
|
|
|
self::$INSTANCE = new ModificationCmdJsonConverter(); |
|
32
|
|
|
} |
|
33
|
|
|
return self::$INSTANCE; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function toJsonObject(/*AbstractProcessInstanceModificationCommand*/$command, bool $isOrQueryActive = false): ?\stdClass |
|
37
|
|
|
{ |
|
38
|
|
|
$json = JsonUtil::createObject(); |
|
39
|
|
|
|
|
40
|
|
|
if ($command instanceof ActivityAfterInstantiationCmd) { |
|
41
|
|
|
JsonUtil::addField($json, self::START_AFTER, $command->getTargetElementId()); |
|
42
|
|
|
} elseif ($command instanceof ActivityBeforeInstantiationCmd) { |
|
43
|
|
|
JsonUtil::addField($json, self::START_BEFORE, $command->getTargetElementId()); |
|
44
|
|
|
} elseif ($command instanceof TransitionInstantiationCmd) { |
|
45
|
|
|
JsonUtil::addField($json, self::START_TRANSITION, $command->getTargetElementId()); |
|
46
|
|
|
} elseif ($command instanceof ActivityCancellationCmd) { |
|
47
|
|
|
JsonUtil::addField($json, self::CANCEL_ALL, $command->getActivityId()); |
|
48
|
|
|
JsonUtil::addField($json, self::CANCEL_CURRENT, $command->isCancelCurrentActiveActivityInstances()); |
|
49
|
|
|
} elseif ($command instanceof ActivityInstanceCancellationCmd) { |
|
50
|
|
|
JsonUtil::addField($json, self::CANCEL_ACTIVITY_INSTANCES, $command->getActivityInstanceId()); |
|
51
|
|
|
JsonUtil::addField($json, self::PROCESS_INSTANCE, $command->getProcessInstanceId()); |
|
52
|
|
|
} elseif ($command instanceof TransitionInstanceCancellationCmd) { |
|
53
|
|
|
JsonUtil::addField($json, self::CANCEL_TRANSITION_INSTANCES, $command->getTransitionInstanceId()); |
|
54
|
|
|
JsonUtil::addField($json, self::PROCESS_INSTANCE, $command->getProcessInstanceId()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $json; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function toObject(\stdClass $json, bool $isOrQuery = false) |
|
61
|
|
|
{ |
|
62
|
|
|
$cmd = null; |
|
63
|
|
|
|
|
64
|
|
|
if (property_exists($json, self::START_BEFORE)) { |
|
65
|
|
|
$cmd = new ActivityBeforeInstantiationCmd(JsonUtil::getString($json, self::START_BEFORE)); |
|
|
|
|
|
|
66
|
|
|
} elseif (property_exists($json, self::START_AFTER)) { |
|
67
|
|
|
$cmd = new ActivityAfterInstantiationCmd(JsonUtil::getString($json, self::START_AFTER)); |
|
|
|
|
|
|
68
|
|
|
} elseif (property_exists($json, self::START_TRANSITION)) { |
|
69
|
|
|
$cmd = new TransitionInstantiationCmd(JsonUtil::getString($json, self::START_TRANSITION)); |
|
|
|
|
|
|
70
|
|
|
} elseif (property_exists($json, self::CANCEL_ALL)) { |
|
71
|
|
|
$cmd = new ActivityCancellationCmd(JsonUtil::getString($json, self::CANCEL_ALL)); |
|
|
|
|
|
|
72
|
|
|
$cancelCurrentActiveActivityInstances = JsonUtil::getBoolean($json, self::CANCEL_CURRENT); |
|
73
|
|
|
$cmd->setCancelCurrentActiveActivityInstances($cancelCurrentActiveActivityInstances); |
|
74
|
|
|
} elseif (property_exists($json, self::CANCEL_ACTIVITY_INSTANCES)) { |
|
75
|
|
|
$cmd = new ActivityInstanceCancellationCmd(JsonUtil::getString($json, self::PROCESS_INSTANCE), JsonUtil::getString($json, self::CANCEL_ACTIVITY_INSTANCES)); |
|
76
|
|
|
} elseif (property_exists($json, self::CANCEL_TRANSITION_INSTANCES)) { |
|
77
|
|
|
$cmd = new TransitionInstanceCancellationCmd(JsonUtil::getString($json, self::PROCESS_INSTANCE), JsonUtil::getString($json, self::CANCEL_TRANSITION_INSTANCES)); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $cmd; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.