-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Demo behavior for Exclusive Gateways
- Loading branch information
Showing
8 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/ProcessMaker/Nayra/Bpmn/ForceGatewayTransitionTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace ProcessMaker\Nayra\Bpmn; | ||
|
||
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; | ||
|
||
/** | ||
* Process base implementation. | ||
*/ | ||
trait ForceGatewayTransitionTrait | ||
{ | ||
use TransitionTrait; | ||
|
||
/** | ||
* Check if the transition should be triggered in debug mode. | ||
* | ||
* @param ExecutionInstanceInterface $executionInstance | ||
* | ||
* @return bool | ||
*/ | ||
function shouldDebugTriggerThisTransition(ExecutionInstanceInterface $executionInstance) | ||
{ | ||
$engine = $executionInstance->getEngine(); | ||
$demoMode = $engine->isDemoMode(); | ||
$gateway = $this->getOwner(); | ||
$connection = $this->outgoing()->item(0); | ||
$targetEntrypoint = $connection->target()->getOwner(); | ||
return $demoMode && $engine->getSelectedDemoFlow($gateway)->getTarget() === $targetEntrypoint; | ||
} | ||
|
||
/** | ||
* Check if the transition should be skipped in debug mode. | ||
* | ||
* @param ExecutionInstanceInterface $executionInstance | ||
* | ||
* @return bool | ||
*/ | ||
function shouldDebugSkipThisTransition(ExecutionInstanceInterface $executionInstance) | ||
{ | ||
$engine = $executionInstance->getEngine(); | ||
$demoMode = $engine->isDemoMode(); | ||
$gateway = $this->getOwner(); | ||
$connection = $this->outgoing()->item(0); | ||
$targetEntrypoint = $connection->target()->getOwner(); | ||
return $demoMode && $engine->getSelectedDemoFlow($gateway)->getTarget() !== $targetEntrypoint; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/ProcessMaker/Nayra/Bpmn/PauseOnGatewayTransitionTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace ProcessMaker\Nayra\Bpmn; | ||
|
||
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; | ||
|
||
/** | ||
* Process base implementation. | ||
*/ | ||
trait PauseOnGatewayTransitionTrait | ||
{ | ||
use TransitionTrait; | ||
|
||
function shouldPauseGatewayTransition(ExecutionInstanceInterface $executionInstance) | ||
{ | ||
$engine = $executionInstance->getEngine(); | ||
$demoMode = $engine->isDemoMode(); | ||
$gateway = $this->getOwner(); | ||
return $demoMode && !$engine->getSelectedDemoFlow($gateway); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace ProcessMaker\Nayra\Engine; | ||
|
||
use ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\GatewayInterface; | ||
|
||
/** | ||
* Implements the engine behavior for debugging. | ||
*/ | ||
trait DemoModeTrait | ||
{ | ||
/** | ||
* Is debug mode enabled | ||
* | ||
* @var bool | ||
*/ | ||
private $demoMode = false; | ||
|
||
/** | ||
* Flow selected by the user in demo mode. | ||
* @var FlowInterface[] | ||
*/ | ||
private $selectedFlows = []; | ||
|
||
/** | ||
* Returns true if the engine is in demo mode. | ||
* | ||
* @return bool | ||
*/ | ||
public function isDemoMode() | ||
{ | ||
return $this->demoMode; | ||
} | ||
|
||
/** | ||
* Set if the engine is in demo mode. | ||
* | ||
* @param bool $value | ||
*/ | ||
public function setDemoMode(bool $value) | ||
{ | ||
$this->demoMode = $value; | ||
} | ||
|
||
/** | ||
* Retrieves the selected flow by the user in demo mode. | ||
* | ||
* @param GatewayInterface $gateway | ||
* | ||
* @return FlowInterface|null | ||
*/ | ||
public function getSelectedDemoFlow(GatewayInterface $gateway) | ||
{ | ||
return $this->selectedFlow[$gateway->getId()] ?? null; | ||
} | ||
|
||
/** | ||
* Set the selected flow by the user in demo mode. | ||
* | ||
* @param GatewayInterface $gateway | ||
* @param bool $value | ||
*/ | ||
public function setSelectedDemoFlow( | ||
GatewayInterface $gateway, | ||
FlowInterface $selectedFlow = null | ||
) { | ||
$this->selectedFlow[$gateway->getId()] = $selectedFlow; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
*/ | ||
trait EngineTrait | ||
{ | ||
use DemoModeTrait; | ||
|
||
/** | ||
* Instances of process. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters