repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/EventBasedGatewayTrait.php
src/ProcessMaker/Nayra/Bpmn/EventBasedGatewayTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface; use ProcessMaker\Nayra\Contracts\Bpmn\GatewayInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StateInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; /** * Base implementation for a event based gateway. */ trait EventBasedGatewayTrait { use ParallelGatewayTrait; /** * @var TransitionInterface */ private $transition; /** * Build the transitions that define the element. * * @param RepositoryInterface $factory */ public function buildTransitions(RepositoryInterface $factory) { $this->setRepository($factory); $this->transition = new ExclusiveGatewayTransition($this); $this->transition->attachEvent(TransitionInterface::EVENT_BEFORE_TRANSIT, function () { $this->notifyEvent(GatewayInterface::EVENT_GATEWAY_ACTIVATED, $this); }); } /** * Get an input to the element. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface|null $targetFlow * * @return StateInterface */ public function getInputPlace(FlowInterface $targetFlow = null) { $incomingPlace = new State($this, GatewayInterface::TOKEN_STATE_INCOMING); $incomingPlace->connectTo($this->transition); $incomingPlace->attachEvent(State::EVENT_TOKEN_ARRIVED, function (TokenInterface $token) { $this->getRepository() ->getTokenRepository() ->persistGatewayTokenArrives($this, $token); $this->notifyEvent(GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES, $this, $token); }); $incomingPlace->attachEvent(State::EVENT_TOKEN_CONSUMED, function (TokenInterface $token) { $this->getRepository() ->getTokenRepository() ->persistGatewayTokenConsumed($this, $token); $this->notifyEvent(GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED, $this, $token); }); return $incomingPlace; } /** * Create a connection to a target node. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface $targetFlow * * @return $this */ protected function buildConnectionTo(FlowInterface $targetFlow) { $target = $targetFlow->getTarget(); $outgoingPlace = new State($this, GatewayInterface::TOKEN_STATE_OUTGOING); $outgoingTransition = new EventBasedTransition($this, $target); $this->transition->connectTo($outgoingPlace); $outgoingPlace->connectTo($outgoingTransition); $outgoingTransition->connectTo($target->getInputPlace($targetFlow)); return $this; } /** * Get the next Event Elements after the gateway * * @return \ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface[] */ public function getNextEventElements() { $nextElements = []; foreach ($this->getOutgoingFlows() as $outgoing) { $nextElements[] = $outgoing->getTarget(); } return new Collection($nextElements); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ProcessTrait.php
src/ProcessMaker/Nayra/Bpmn/ProcessTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ArtifactCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\DataStoreCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\DataStoreInterface; use ProcessMaker\Nayra\Contracts\Bpmn\DiagramInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EndEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowElementInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\GatewayCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\GatewayInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StartEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\EngineInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; /** * Process base implementation. */ trait ProcessTrait { use BaseTrait, ObservableTrait { addProperty as baseAddProperty; notifyEvent as public; } /** * @var \ProcessMaker\Nayra\Contracts\EventBusInterface */ private $dispatcher; /** * @var ExecutionInstanceInterface[] */ private $instances; /** * @var \ProcessMaker\Nayra\Contracts\Engine\EngineInterface */ private $engine; /** * @var \ProcessMaker\Nayra\Contracts\Engine\TransitionInterface[] */ private $transitions = null; /** * Initialize the process element. */ protected function initProcessTrait() { $this->instances = new Collection; $this->setLaneSets(new Collection); } /** * @return \ProcessMaker\Nayra\Contracts\Bpmn\ActivityCollectionInterface */ public function getActivities() { return $this->getProperty('activities'); } /** * Get data stores. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\DataStoreCollectionInterface */ public function getDataStores() { return $this->getProperty('dataStores'); } /** * Get artifacts. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\ArtifactCollectionInterface */ public function getArtifacts() { return $this->getProperty('artifacts'); } /** * Get diagram * * @return \ProcessMaker\Nayra\Contracts\Bpmn\DiagramInterface */ public function getDiagram() { return $this->getProperty('diagram'); } /** * Get events. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\EventCollectionInterface */ public function getEvents() { return $this->getProperty('events'); } /** * Get flows. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\FlowCollectionInterface */ public function getFlows() { return $this->getProperty('flows'); } /** * Get gateways. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\GatewayCollectionInterface */ public function getGateways() { return $this->getProperty('gateways'); } /** * Set activities collection. * * @param ActivityCollectionInterface $activities * * @return $this */ public function setActivities(ActivityCollectionInterface $activities) { $this->setProperty('activities', $activities); return $this; } /** * Set data stores collection. * * @param DataStoreCollectionInterface $dataStores * * @return $this */ public function setDataStores(DataStoreCollectionInterface $dataStores) { $this->setProperty('dataStores', $dataStores); return $this; } /** * Set artifacts collection. * * @param ArtifactCollectionInterface $artifacts * * @return $this */ public function setArtifacts(ArtifactCollectionInterface $artifacts) { $this->setProperty('artifacts', $artifacts); return $this; } /** * Set diagram. * * @param DiagramInterface $diagram * * @return $this */ public function setDiagram(DiagramInterface $diagram) { $this->setProperty('diagram', $diagram); return $this; } /** * Set events collection. * * @param EventCollectionInterface $events * * @return $this */ public function setEvents(EventCollectionInterface $events) { $this->setProperty('events', $events); return $this; } /** * Set flows collection. * * @param FlowCollectionInterface $flows * * @return $this */ public function setFlows(FlowCollectionInterface $flows) { $this->setProperty('flows', $flows); return $this; } /** * Get gateways collection. * * @param GatewayCollectionInterface $gateways * * @return $this */ public function setGateways(GatewayCollectionInterface $gateways) { $this->setProperty('gateways', $gateways); return $this; } /** * Add value to collection property and set the process as owner. * * @param string $name * @param mixed $value * * @return $this */ public function addProperty($name, $value) { $this->baseAddProperty($name, $value); if ($value instanceof FlowElementInterface) { $value->setOwnerProcess($this); } return $this; } /** * Get transitions of the process. * * @param RepositoryInterface $factory * * @return CollectionInterface */ public function getTransitions(RepositoryInterface $factory) { if ($this->transitions) { return $this->transitions; } //Build the runtime elements foreach ($this->getProperty('events') as $event) { $event->buildTransitions($factory); } foreach ($this->getProperty('activities') as $activity) { $activity->buildTransitions($factory); } foreach ($this->getProperty('gateways') as $gateway) { $gateway->buildTransitions($factory); } //Build the runtime flows foreach ($this->getProperty('events') as $event) { $event->buildFlowTransitions($factory); } foreach ($this->getProperty('activities') as $activity) { $activity->buildFlowTransitions($factory); } foreach ($this->getProperty('gateways') as $gateway) { $gateway->buildFlowTransitions($factory); } //Get the transitions $transitions = []; foreach ($this->getProperty('events') as $event) { $transitions = array_merge($transitions, $event->getTransitions()); } foreach ($this->getProperty('activities') as $activity) { $transitions = array_merge($transitions, $activity->getTransitions()); } foreach ($this->getProperty('gateways') as $gateway) { $transitions = array_merge($transitions, $gateway->getTransitions()); } // Catch end events and cancel activities to check if the process was completed $this->attachEvent(EndEventInterface::EVENT_EVENT_TRIGGERED, [$this, 'checkProcessCompleted']); $this->attachEvent(ActivityInterface::EVENT_ACTIVITY_CANCELLED, [$this, 'checkProcessCompleted']); $this->transitions = new Collection($transitions); return $this->transitions; } /** * Check if the process was completed * * @param FlowNodeInterface $node * @param TransitionInterface $transition * @param CollectionInterface $tokens */ public function checkProcessCompleted(FlowNodeInterface $node, TransitionInterface $transition, CollectionInterface $tokens) { $instance = $tokens->item(0)->getInstance(); if ($instance->getTokens()->count() !== 0) { return; } $instanceRepo = $this->getRepository()->createExecutionInstanceRepository(); $instanceRepo->persistInstanceCompleted($instance); $this->notifyInstanceEvent(ProcessInterface::EVENT_PROCESS_INSTANCE_COMPLETED, $instance, $node); } /** * Notify an process instance event. * * @param string $eventName * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $instance * @param mixed $event * * @return $this */ public function notifyInstanceEvent($eventName, ExecutionInstanceInterface $instance, $event = null) { $this->notifyEvent($eventName, $this, $instance, $event); $arguments = [$this, $instance, $event]; $bpmnEvents = $this->getBpmnEventClasses(); $payload = new $bpmnEvents[$eventName](...$arguments); $this->getDispatcher()->dispatch($eventName, $payload); return $this; } /** * Add an activity. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface $activity * @return $this */ public function addActivity(ActivityInterface $activity) { $activity->setOwnerProcess($this); $this->getProperty('activities')->push($activity); return $this; } /** * Add an event * * @param \ProcessMaker\Nayra\Contracts\Bpmn\EventInterface $event * * @return $this */ public function addEvent(EventInterface $event) { $event->setOwnerProcess($this); $event->setProcess($this); $this->getProperty('events')->push($event); return $this; } /** * Add a gateway * * @param \ProcessMaker\Nayra\Contracts\Bpmn\GatewayInterface $gateway * * @return $this */ public function addGateway(GatewayInterface $gateway) { $gateway->setOwnerProcess($this); $this->getProperty('gateways')->push($gateway); return $this; } /** * @param \ProcessMaker\Nayra\Contracts\EventBusInterface $dispatcher * * @return \ProcessMaker\Nayra\Contracts\EventBusInterface */ public function getDispatcher() { return $this->dispatcher; } /** * @param mixed $dispatcher * * @return $this */ public function setDispatcher($dispatcher) { $this->dispatcher = $dispatcher; return $this; } /** * Get the loaded process instances. * * @return \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface[] */ public function getInstances() { return $this->instances; } /** * Add process instance reference. * * @param ExecutionInstanceInterface $instance * * @return $this */ public function addInstance(ExecutionInstanceInterface $instance) { $this->instances->push($instance); return $this; } /** * Set the engine that controls the elements. * * @param EngineInterface|null $engine * * @return EngineInterface */ public function setEngine(EngineInterface $engine = null) { $this->engine = $engine; return $this; } /** * Get the engine that controls the elements. * * @return EngineInterface */ public function getEngine() { return $this->engine; } /** * Create an instance of the callable element and start it. * * @param DataStoreInterface|null $dataStore * @param StartEventInterface|null $selectedStart * * @return ExecutionInstanceInterface */ public function call(DataStoreInterface $dataStore = null, StartEventInterface $selectedStart = null) { if (empty($dataStore)) { $dataStore = $this->getRepository()->createDataStore(); } $instance = $this->getEngine()->createExecutionInstance($this, $dataStore); $this->getEvents()->find(function (EventInterface $event) use ($instance, $selectedStart) { if ($event instanceof StartEventInterface && $event->getEventDefinitions()->count() === 0 && ($selectedStart === null || $selectedStart->getId() === $event->getId())) { $event->start($instance); } }); return $instance; } /** * Get the lane sets of the process. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\LaneSetInterface[] */ public function getLaneSets() { return $this->getProperty(ProcessInterface::BPMN_PROPERTY_LANE_SET); } /** * Set the lane sets of the process * * @param CollectionInterface $laneSets * * @return $this */ public function setLaneSets(CollectionInterface $laneSets) { $this->setProperty(ProcessInterface::BPMN_PROPERTY_LANE_SET, $laneSets); return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/InvalidDataInputTransition.php
src/ProcessMaker/Nayra/Bpmn/InvalidDataInputTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ConnectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ErrorInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition to check if the activity is a loop with an invalid data input */ class InvalidDataInputTransition implements TransitionInterface { use TransitionTrait; /** * Condition required to transit the element. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface|null $token * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { $loop = $this->getOwner()->getLoopCharacteristics(); return $loop && $loop->isExecutable() && !$loop->isDataInputValid($executionInstance, $token); } /** * Get transition owner element * * @return ActivityInterface */ public function getOwner() { return $this->owner; } /** * Activate the next state. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\ConnectionInterface $flow * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $instance * @param \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface $consumeTokens * @param array $properties * @param \ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface|null $source * * @return TokenInterface */ protected function activateNextState(ConnectionInterface $flow, ExecutionInstanceInterface $instance, CollectionInterface $consumeTokens, array $properties = [], TransitionInterface $source = null) { $loop = $this->getOwner()->getLoopCharacteristics(); if ($loop && $loop->isExecutable()) { foreach ($consumeTokens as $token) { $errorMessage = $loop->getDataInputError($instance, $token); } $error = $this->getOwner()->getRepository()->createError(); $error->setId('INVALID_DATA_INPUT'); $error->setName($errorMessage); $properties['error'] = $error; $properties[TokenInterface::BPMN_PROPERTY_EVENT_ID] = null; $properties[TokenInterface::BPMN_PROPERTY_EVENT_DEFINITION_CAUGHT] = null; $properties[TokenInterface::BPMN_PROPERTY_EVENT_TYPE] = ErrorInterface::class; $flow->targetState()->addNewToken($instance, $properties, $source); } } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/IntermediateCatchEventTransition.php
src/ProcessMaker/Nayra/Bpmn/IntermediateCatchEventTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition rule to consume tokens in an End Event. */ class IntermediateCatchEventTransition implements TransitionInterface { use TransitionTrait; /** * Condition required at end event. * * @param TokenInterface|null $token * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { return true; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/BoundaryEventTrait.php
src/ProcessMaker/Nayra/Bpmn/BoundaryEventTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Bpmn\Models\ErrorEventDefinition; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\BoundaryEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ErrorEventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ErrorInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StateInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\EngineInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; /** * Boundary event implementation. * * @see \ProcessMaker\Nayra\Contracts\Bpmn\BoundaryEventInterface */ trait BoundaryEventTrait { use CatchEventTrait; /** * @var StateInterface */ private $activeState; /** * @var TransitionInterface */ private $outgoingTransition; /** * Build the transitions that define the element. * * @param RepositoryInterface $factory */ public function buildTransitions(RepositoryInterface $factory) { $this->setRepository($factory); $this->transition = new Transition($this, true); $this->outgoingTransition = new Transition($this); $this->interruptActivityTransition = new BoundaryInterruptActivityTransition($this, true); $this->noInterruptActivityTransition = new BoundaryNoInterruptActivityTransition($this, true); $this->activeState = new State($this, BoundaryEventInterface::TOKEN_STATE_ACTIVE); $this->completedState = new State($this, BoundaryEventInterface::TOKEN_STATE_COMPLETED); $this->transition->connectTo($this->activeState); $this->activeState->connectTo($this->interruptActivityTransition); $this->activeState->connectTo($this->noInterruptActivityTransition); $this->noInterruptActivityTransition->connectTo($this->completedState); $this->completedState->connectTo($this->outgoingTransition); $this->buildEventDefinitionsTransitions( BoundaryEventInterface::EVENT_BOUNDARY_EVENT_CATCH, BoundaryEventInterface::EVENT_BOUNDARY_EVENT_CONSUMED ); $this->interruptActivityTransition->attachEvent(Transition::EVENT_AFTER_TRANSIT, function ($transition, Collection $tokens) { $activity = $this->getAttachedTo(); foreach ($tokens as $token) { $eventType = $token->getProperty(TokenInterface::BPMN_PROPERTY_EVENT_TYPE); $isError = $eventType === ErrorInterface::class || is_a($eventType, ErrorInterface::class); if (!$isError && $this->getCancelActivity() && $activity instanceof ActivityInterface) { $activity->notifyInterruptingEvent($token); break; } } }); } /** * Get an input to the element. Boundary event does not have an input place. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface|null $targetFlow * * @return StateInterface */ public function getInputPlace(FlowInterface $targetFlow = null) { return null; } /** * Create a connection to a target node. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface $targetFlow * * @return $this */ protected function buildConnectionTo(FlowInterface $targetFlow) { $this->outgoingTransition->connectTo($targetFlow->getTarget()->getInputPlace($targetFlow)); return $this; } /** * Register the BPMN elements with the engine. * * @param EngineInterface $engine * * @return FlowElementInterface */ public function registerWithEngine(EngineInterface $engine) { // Register Catch Events, except Errors that will be catch through EVENT_ACTIVITY_EXCEPTION foreach ($this->getEventDefinitions() as $eventDefinition) { if ($eventDefinition instanceof ErrorEventDefinitionInterface) { continue; } $eventDefinition->registerWithCatchEvent($engine, $this); } // Schedule timer events when Activity is Activated $this->getAttachedTo()->attachEvent(ActivityInterface::EVENT_ACTIVITY_ACTIVATED, function (ActivityInterface $activity, TokenInterface $token) { $this->activateCatchEvent($token); }); // Catch EVENT_ACTIVITY_EXCEPTION $this->getAttachedTo()->attachEvent(ActivityInterface::EVENT_ACTIVITY_EXCEPTION, function (ActivityInterface $activity, TokenInterface $token) { $error = $token->getProperty(ErrorEventDefinitionInterface::BPMN_PROPERTY_ERROR); $this->catchErrorEvent($token, $error); }); return $this; } /** * Catch an error event message * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface $token * @param \ProcessMaker\Nayra\Contracts\Bpmn\ErrorInterface|null $error */ private function catchErrorEvent(TokenInterface $token, ErrorInterface $error = null) { $errorDef = new ErrorEventDefinition(); $error ? $errorDef->setError($error) : null; foreach ($this->getEventDefinitions() as $index => $eventDefinition) { if ($eventDefinition instanceof ErrorEventDefinitionInterface && $eventDefinition->shouldCatchEventDefinition($errorDef)) { $properties = [ TokenInterface::BPMN_PROPERTY_EVENT_ID => null, TokenInterface::BPMN_PROPERTY_EVENT_DEFINITION_CAUGHT => $eventDefinition->getId(), TokenInterface::BPMN_PROPERTY_EVENT_TYPE => ErrorInterface::class, ]; $this->triggerPlace[$index]->addNewToken($token->getInstance(), $properties); } } } /** * Denotes whether the Activity should be cancelled or not. * * @return bool */ public function getCancelActivity() { return $this->getProperty(BoundaryEventInterface::BPMN_PROPERTY_CANCEL_ACTIVITY, true); } /** * Set if the Activity should be cancelled or not. * * @param bool $cancelActivity * * @return BoundaryEventInterface */ public function setCancelActivity($cancelActivity) { return $this->setProperty(BoundaryEventInterface::BPMN_PROPERTY_CANCEL_ACTIVITY, $cancelActivity); } /** * Get the Activity that boundary Event is attached to. * * @return ActivityInterface */ public function getAttachedTo() { return $this->getProperty(BoundaryEventInterface::BPMN_PROPERTY_ATTACHED_TO); } /** * Set the Activity that boundary Event is attached to. * * @param ActivityInterface $activity * * @return BoundaryEventInterface */ public function setAttachedTo(ActivityInterface $activity) { return $this->setProperty(BoundaryEventInterface::BPMN_PROPERTY_ATTACHED_TO, $activity); } /** * Get the active state of the element * * @return StateInterface */ public function getActiveState() { return $this->getAttachedTo()->getActiveState(); } /** * Notify to complete the boundary event. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface $token */ public function notifyInternalEvent(TokenInterface $token) { $instance = $token->getInstance(); $properties = $token->getProperties(); $this->completedState->addNewToken($instance, $properties); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/FlowElementTrait.php
src/ProcessMaker/Nayra/Bpmn/FlowElementTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; /** * Flow Element is an abstract class for all the elements that can appear in * a Process. */ trait FlowElementTrait { use BaseTrait; /** * Owner process. * * @var ProcessInterface */ private $ownerProcess; /** * Get the owner process. * * @return ProcessInterface */ public function getOwnerProcess() { return $this->ownerProcess; } /** * Set the owner process. * * @param ProcessInterface $ownerProcess * * @return $this */ public function setOwnerProcess(ProcessInterface $ownerProcess) { $this->ownerProcess = $ownerProcess; return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ParallelGatewayTransition.php
src/ProcessMaker/Nayra/Bpmn/ParallelGatewayTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition rule for a parallel gateway. */ class ParallelGatewayTransition implements TransitionInterface { use TransitionTrait; use PauseOnGatewayTransitionTrait; /** * Always true because the conditions are not defined in the gateway, but for each * outgoing flow transition. * * @param TokenInterface|null $token * @param ExecutionInstanceInterface|null $executionInstance * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { return !$this->shouldPauseGatewayTransition($executionInstance); } /** * The Parallel Gateway is activated if there is at least one token on * each incoming Sequence Flow. * * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $executionInstance * * @return bool */ protected function hasAllRequiredTokens(ExecutionInstanceInterface $executionInstance) { if ($this->doesDemoHasAllRequiredTokens($executionInstance)) { return true; } $incomingWithToken = $this->incoming()->find(function (Connection $flow) use ($executionInstance) { return $flow->originState()->getTokens($executionInstance)->count() > 0; }); return $incomingWithToken->count() === $this->incoming()->count() && $incomingWithToken->count() > 0; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/BoundaryExceptionTransition.php
src/ProcessMaker/Nayra/Bpmn/BoundaryExceptionTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Bpmn\Models\ErrorEventDefinition; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\BoundaryEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ErrorInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Boundary Caught Transition. */ class BoundaryExceptionTransition implements TransitionInterface { use TransitionTrait; /** * Condition required to transit the element. * * @param TokenInterface|null $token * @param ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { $activity = $this->getOwner(); $eventType = $token->getProperty(TokenInterface::BPMN_PROPERTY_EVENT_TYPE); return $this->existsBoundaryErrorFor($activity, $eventType, null); } /** * Check if activity has a boundary event for the given event definition. * * @param ActivityInterface $activity * @param string $eventType * * @return bool */ protected function existsBoundaryErrorFor(ActivityInterface $activity, $eventType) { $catchException = $activity->getBoundaryEvents()->findFirst(function (BoundaryEventInterface $catch) use ($eventType) { foreach ($catch->getEventDefinitions() as $eventDefinition) { if ($eventDefinition instanceof ErrorEventDefinition) { $matchType = $eventType === ErrorInterface::class || is_a($eventType, ErrorInterface::class); return $matchType && $catch->getCancelActivity(); } } }); return !empty($catchException); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/LoopCharacteristicsTrait.php
src/ProcessMaker/Nayra/Bpmn/LoopCharacteristicsTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\LoopCharacteristicsInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Base implementation for LoopCharacteristicsInterface */ trait LoopCharacteristicsTrait { use BaseTrait; /** * Prepare Loop Instance properties for execution * * @param TokenInterface $token * @param array $properties * * @return array */ private function prepareLoopInstanceProperties(TokenInterface $token, array $properties = []) { $loopCharacteristics = $token->getProperty( LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, $properties[LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY] ?? [] ); if (empty($loopCharacteristics['sourceToken'])) { $loopCharacteristics['sourceToken'] = $token->getId(); } $properties[LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY] = $loopCharacteristics; $token->setProperty( LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, $properties[LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY] ); return $properties; } /** * Set Loop Instance property during execution * * @param TokenInterface $token * @param string $key * @param mixed $value * * @return self */ private function setLoopInstanceProperty(TokenInterface $token, $key, $value) { $loopCharacteristics = $token->getProperty(LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, []); $outerInstance = $loopCharacteristics['sourceToken']; $ds = $token->getInstance()->getDataStore(); $data = $ds->getData(LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, []); $data[$outerInstance] = $data[$outerInstance] ?? []; $data[$outerInstance][$key] = $value; $ds->putData(LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, $data); return $this; } /** * Get Loop Instance property during execution * * @param TokenInterface $token * @param string $key * @param mixed $defaultValue * * @return mixed */ public function getLoopInstanceProperty(TokenInterface $token, $key, $defaultValue = null) { $loopCharacteristics = $token->getProperty(LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, []); if (!isset($loopCharacteristics['sourceToken'])) { return $defaultValue; } $outerInstance = $loopCharacteristics['sourceToken']; $ds = $token->getInstance()->getDataStore(); $data = $ds->getData(LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, []); $data[$outerInstance] = $data[$outerInstance] ?? []; return $data[$outerInstance][$key] ?? $defaultValue; } /** * Check if data input is valid * * @param ExecutionInstanceInterface $instance * @param TokenInterface $token * * @return bool */ public function isDataInputValid(ExecutionInstanceInterface $instance, TokenInterface $token) { // todo: check if data input is valid return true; } /** * @param TokenInterface $token * * @return void */ public function onTokenCompleted(TokenInterface $token) { //required for internal validation } /** * Merge output data into instance data * * @param CollectionInterface $consumedTokens * @param ExecutionInstanceInterface $instance * * @return void */ public function mergeOutputData(CollectionInterface $consumedTokens, ExecutionInstanceInterface $instance) { //required for internal validation } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/CloseExceptionTransition.php
src/ProcessMaker/Nayra/Bpmn/CloseExceptionTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition rule to close an activity in FAILING state. */ class CloseExceptionTransition implements TransitionInterface { use TransitionTrait; /** * Initialize transition. */ protected function initActivityTransition() { $this->setPreserveToken(true); } /** * Condition required to transit an activity in FAILING state. * * @param TokenInterface|null $token * @param ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { return $token->getStatus() === ActivityInterface::TOKEN_STATE_CLOSED; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/PauseOnGatewayTransitionTrait.php
src/ProcessMaker/Nayra/Bpmn/PauseOnGatewayTransitionTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Process base implementation. */ trait PauseOnGatewayTransitionTrait { use TransitionTrait; /** * Check if the gateway should pause the transition. * * @param ExecutionInstanceInterface $executionInstance * * @return bool */ function shouldPauseGatewayTransition(ExecutionInstanceInterface $executionInstance) { $engine = $executionInstance->getEngine(); $demoMode = $engine->isDemoMode(); $gateway = $this->getOwner(); return $demoMode && !$engine->getSelectedDemoFlow($gateway); } /** * Check if the gateway input has at least one token in demo mode. * * @param ExecutionInstanceInterface $executionInstance * @return bool */ function doesDemoHasAllRequiredTokens(ExecutionInstanceInterface $executionInstance) { $engine = $executionInstance->getEngine(); $demoMode = $engine->isDemoMode(); if (!$demoMode) { return false; } $withToken = $this->incoming()->find(function (Connection $flow) use ($executionInstance) { return $flow->originState()->getTokens($executionInstance)->count() > 0; }); return $withToken->count() > 0; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ObservableTrait.php
src/ProcessMaker/Nayra/Bpmn/ObservableTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\StateInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; /** * Observable behavior. */ trait ObservableTrait { private $observers = []; /** * Returns the list of observers of the object * * @return array */ public function getObservers() { return $this->observers; } /** * Attach a callback to an event. * * @param string $event * @param callable $callback */ public function attachEvent($event, callable $callback) { $this->observers[$event][] = $callback; } /** * Detach a callback from an event. * * @param string $event * @param callable $callback */ public function detachEvent($event, callable $callback) { $index = array_search($callback, $this->observers[$event], true); if ($index !== false) { unset($this->observers[$event][$index]); } } /** * Notify a event to the observers. * * @param $event * @param array ...$arguments */ protected function notifyEvent($event, ...$arguments) { if (empty($this->observers[$event])) { return; } foreach ($this->observers[$event] as $callback) { call_user_func_array($callback, $arguments); } } /** * Notify an external event to the observers. * * @param $event * @param array ...$arguments */ public function notifyExternalEvent($event, ...$arguments) { $this->notifyEvent($event, ...$arguments); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ExceptionTransition.php
src/ProcessMaker/Nayra/Bpmn/ExceptionTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ErrorInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition rule when a exception is catch. */ class ExceptionTransition implements TransitionInterface { use TransitionTrait; /** * Initialize transition. */ protected function initActivityTransition() { $this->setPreserveToken(true); } /** * Condition required to transit the element. * * @param TokenInterface|null $token * @param ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { return $token->getStatus() === ActivityInterface::TOKEN_STATE_FAILING; } /** * Mark token as error event. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface $token */ protected function onTokenTransit(TokenInterface $token) { $token->setProperty(TokenInterface::BPMN_PROPERTY_EVENT_TYPE, ErrorInterface::class); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/SkipActivityTransition.php
src/ProcessMaker/Nayra/Bpmn/SkipActivityTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StandardLoopCharacteristicsInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition rule that always pass the token. */ class SkipActivityTransition implements TransitionInterface { use TransitionTrait; /** * Initialize the transition. * * @param FlowNodeInterface $owner * @param bool $preserveToken */ protected function initDataOutputTransition() { $this->setTokensConsumedPerIncoming(-1); } /** * Condition required to transit the element. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface|null $token * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { $loop = $this->getOwner()->getLoopCharacteristics(); if ($loop instanceof StandardLoopCharacteristicsInterface) { $testBefore = $loop->getTestBefore(); $completed = $loop->isLoopCompleted($executionInstance, $token); // If loop is completed, then Skip Activity Transition is triggered return $testBefore && $completed; } return false; } /** * Get transition owner element * * @return ActivityInterface */ public function getOwner() { return $this->owner; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ActivityCompletedTransition.php
src/ProcessMaker/Nayra/Bpmn/ActivityCompletedTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition rule for an activity. */ class ActivityCompletedTransition implements TransitionInterface { use TransitionTrait; /** * Condition required to transit the element. * * @param TokenInterface|null $token * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { return $token->getStatus() === ActivityInterface::TOKEN_STATE_COMPLETED; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ActivitySubProcessTrait.php
src/ProcessMaker/Nayra/Bpmn/ActivitySubProcessTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EndEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ErrorEventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ErrorInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Sub-Process/Call Activity base implementation. */ trait ActivitySubProcessTrait { use ActivityTrait; /** * Configure the activity to go to a FAILING status when activated. */ protected function initActivity() { $this->attachEvent( ActivityInterface::EVENT_ACTIVITY_ACTIVATED, function ($self, TokenInterface $token) { $instance = $this->callSubprocess($token); $this->linkProcesses($token, $instance); } ); } /** * Call the subprocess * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface $token * * @return ExecutionInstanceInterface */ protected function callSubprocess(TokenInterface $token) { $dataStore = $this->getRepository()->createDataStore(); $dataStore->setData($token->getInstance()->getDataStore()->getData()); return $this->getCalledElement()->call($dataStore); } /** * Links parent and sub process in a CallActivity * * @param TokenInterface $token * @param ExecutionInstanceInterface $instance * * @return void */ private function linkProcesses(TokenInterface $token, ExecutionInstanceInterface $instance) { $this->getCalledElement()->attachEvent( ProcessInterface::EVENT_PROCESS_INSTANCE_COMPLETED, function ($self, ExecutionInstanceInterface $closedInstance) use ($token, $instance) { $skipStates = [ ActivityInterface::TOKEN_STATE_FAILING, ActivityInterface::TOKEN_STATE_INTERRUPTED, ]; if ($closedInstance->getId() === $instance->getId() && !in_array($token->getStatus(), $skipStates)) { $this->completeSubprocess($token, $closedInstance, $instance); } } ); $this->getCalledElement()->attachEvent( ErrorEventDefinitionInterface::EVENT_THROW_EVENT_DEFINITION, function ($element, $innerToken, $error) use ($token, $instance) { if ($innerToken->getInstance() === $instance) { $this->catchSubprocessError($token, $error, $instance); } } ); $this->getCalledElement()->attachEvent( ActivityInterface::EVENT_ACTIVITY_EXCEPTION, function ($element, $innerToken, $error) use ($token, $instance) { $elementHasErrorBoundary = $this->checkHasErrorBoundary($element); if (!$elementHasErrorBoundary && $innerToken->getInstance() === $instance) { $this->catchSubprocessError($token, $error, $instance); } } ); $this->attachEvent( ActivityInterface::EVENT_ACTIVITY_CANCELLED, function ($activity, $transition, $tokens) use ($token, $instance) { $belongsTo = false; foreach ($tokens as $cancelled) { $belongsTo |= $cancelled->getInstance()->getId() === $token->getInstance()->getId(); } $belongsTo ? $this->cancelSubprocess($instance) : null; } ); } /** * Check if the element has an error boundary * * @param mixed $element * * @return bool */ private function checkHasErrorBoundary($element) { $elementHasErrorBoundary = false; foreach($element->getBoundaryEvents() as $boundary) { if ($boundary->getEventDefinitions()->item(0) instanceof ErrorEventDefinitionInterface) { $elementHasErrorBoundary = true; } } return $elementHasErrorBoundary; } /** * Complete the subprocess * * @param TokenInterface $token * @return void */ protected function completeSubprocess(TokenInterface $token) { $token->setStatus(ActivityInterface::TOKEN_STATE_COMPLETED); } /** * Catch a subprocess error * * @param TokenInterface $token * @param ErrorInterface|null $error * * @return ActivityInterface */ protected function catchSubprocessError(TokenInterface $token, ErrorInterface $error = null) { $token->setStatus(ActivityInterface::TOKEN_STATE_FAILING); $token->setProperty(ErrorEventDefinitionInterface::BPMN_PROPERTY_ERROR, $error); return $this; } /** * Cancel a subprocess * * @param ExecutionInstanceInterface|null $instance * * @return ActivityInterface */ protected function cancelSubprocess(ExecutionInstanceInterface $instance = null) { $instance ? $instance->close() : null; return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/StartEventTrait.php
src/ProcessMaker/Nayra/Bpmn/StartEventTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EndEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageEventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ThrowEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\EngineInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; /** * Implementation of the behavior of a start event. */ trait StartEventTrait { use CatchEventTrait; /** * @var StartTransition */ private $transition; /** * @var \ProcessMaker\Nayra\Contracts\Bpmn\StateInterface */ private $triggerPlace = []; /** * Build the transitions of the element. * * @param RepositoryInterface $factory */ public function buildTransitions(RepositoryInterface $factory) { $this->setRepository($factory); $this->transition = new Transition($this); $this->transition->attachEvent( TransitionInterface::EVENT_BEFORE_TRANSIT, function (TransitionInterface $transition, CollectionInterface $consumeTokens) { $this->getRepository() ->getTokenRepository() ->persistStartEventTriggered($this, $consumeTokens); $this->notifyEvent(EventInterface::EVENT_EVENT_TRIGGERED, $this, $transition, $consumeTokens); } ); $eventDefinitions = $this->getEventDefinitions(); foreach ($eventDefinitions as $index => $eventDefinition) { $this->triggerPlace[$index] = new State($this, $eventDefinition->getId()); $this->triggerPlace[$index]->connectTo($this->transition); } if ($eventDefinitions->count() === 0) { $this->triggerPlace[0] = new State($this); $this->triggerPlace[0]->connectTo($this->transition); } } /** * Get the input place. Start event does not have an input place. * * @param FlowInterface|null $targetFlow * * @return null */ public function getInputPlace(FlowInterface $targetFlow = null) { return null; } /** * Create a flow to a target node. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface $targetFlow * * @return $this */ protected function buildConnectionTo(FlowInterface $targetFlow) { $this->transition->connectTo($targetFlow->getTarget()->getInputPlace($targetFlow)); return $this; } /** * Start event. * * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $instance * * @return $this; */ public function start(ExecutionInstanceInterface $instance) { $this->triggerPlace[0]->addNewToken($instance); return $this; } /** * Method to be called when a message event arrives * * @param EventDefinitionInterface $eventDef * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return $this */ public function execute(EventDefinitionInterface $eventDef, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { foreach ($this->getEventDefinitions() as $index => $eventDefinition) { if ($eventDefinition->assertsRule($eventDef, $this, $instance, $token)) { if ($instance === null) { $process = $this->getOwnerProcess(); $data = $eventDefinition->getPayloadData($token, $this); $dataStorage = $process->getRepository()->createDataStore(); $sourceHasDataMapping = $token?->getOwnerElement()?->getDataInputs()?->count(); $targetHasDataMapping = $this->getDataOutputAssociations()?->count(); if (!$sourceHasDataMapping && !$targetHasDataMapping) { $dataStorage->setData($data); } $instance = $process->getEngine()->createExecutionInstance($process, $dataStorage); } $this->triggerPlace[$index]->addNewToken($instance); $eventDefinition->execute($eventDef, $this, $instance, $token); } } return $this; } /** * Register the BPMN elements with the engine. * * @param EngineInterface $engine * * @return FlowElementInterface */ public function registerWithEngine(EngineInterface $engine) { $this->registerCatchEvents($engine); $this->activateCatchEvent(null); return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/MessageFlowTrait.php
src/ProcessMaker/Nayra/Bpmn/MessageFlowTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Bpmn\EndTransition; use ProcessMaker\Nayra\Bpmn\State; use ProcessMaker\Nayra\Contracts\Bpmn\EventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StateInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Repositories\StorageInterface; use ProcessMaker\Nayra\Exceptions\InvalidSequenceFlowException; /** * End event behavior's implementation. */ trait MessageFlowTrait { use BaseTrait; }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/CompleteExceptionTransition.php
src/ProcessMaker/Nayra/Bpmn/CompleteExceptionTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition rule for an activity in FAILING state. */ class CompleteExceptionTransition implements TransitionInterface { use TransitionTrait; /** * Initialize transition. */ protected function initActivityTransition() { $this->setPreserveToken(true); } /** * Condition required to transit an activity in FAILING state. * * @param TokenInterface|null $token * @param ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { return $token->getStatus() === ActivityInterface::TOKEN_STATE_COMPLETED; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ParticipantTrait.php
src/ProcessMaker/Nayra/Bpmn/ParticipantTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ParticipantInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; /** * Participant class */ trait ParticipantTrait { use BaseTrait; /** * @var mixed[] */ private $interfaces; /** * @var mixed[] */ private $endPoints; /** * Initialize the default values for the participant element. */ protected function initParticipant() { $default = ['maximum' => 1, 'minimum' => 0]; $this->setProperty(ParticipantInterface::BPMN_PROPERTY_PARTICIPANT_MULTIPICITY, $default); } /** * Returns the process associated to the participant * * @return \ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface */ public function getProcess() { return $this->getProperty(ParticipantInterface::BPMN_PROPERTY_PROCESS); } /** * Set the Process that the Participant uses in the Collaboration. * * @param ProcessInterface $process * * @return $this */ public function setProcess(ProcessInterface $process) { $this->setProperty(ParticipantInterface::BPMN_PROPERTY_PROCESS, $process); $process->addProperty(ProcessInterface::BPMN_PROPERTY_PARTICIPANT, $this); return $this; } /** * Get Participant multiplicity for a given interaction. * * @return array */ public function getParticipantMultiplicity() { return $this->getProperty(ParticipantInterface::BPMN_PROPERTY_PARTICIPANT_MULTIPICITY); } /** * Set Participant multiplicity for a given interaction. * * @param array $array * * @return $this */ public function setParticipantMultiplicity(array $array) { return $this->setProperty(ParticipantInterface::BPMN_PROPERTY_PARTICIPANT_MULTIPICITY, $array); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/BoundaryInterruptActivityTransition.php
src/ProcessMaker/Nayra/Bpmn/BoundaryInterruptActivityTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\BoundaryEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Check if Boundary cancels the Activity. */ class BoundaryInterruptActivityTransition implements TransitionInterface { use TransitionTrait; /** * Condition required to transit the element. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface|null $token * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { $boundary = $this->getOwner(); $interrupt = false; if ($boundary instanceof BoundaryEventInterface) { $interrupt = $boundary->getCancelActivity(); } return $interrupt; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/TransitionTrait.php
src/ProcessMaker/Nayra/Bpmn/TransitionTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ConnectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowElementInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Control the transition of tokens through states. */ trait TransitionTrait { use FlowElementTrait, TraversableTrait, ObservableTrait; /** * Flow node owner of the transition. * * @var FlowNodeInterface */ protected $owner; /** * How many tokens are consumed per transition. * (0 or -1 = Means no limit) * * @var int */ private $tokensConsumedPerTransition = -1; /** * How many tokens are consumed per incoming. * (0 or -1 = Means no limit) * * @var int */ private $tokensConsumedPerIncoming = 1; /** * @var bool */ private $preserveToken = false; /** * Initialize the transition. * * @param FlowNodeInterface $owner * @param bool $preserveToken */ protected function initTransition(FlowNodeInterface $owner, $preserveToken = false) { $this->owner = $owner; $owner->addTransition($this); $this->setPreserveToken($preserveToken); } /** * Evaluate true if all the incoming has at least one token. * * @param ExecutionInstanceInterface $instance * * @return bool */ protected function hasAllRequiredTokens(ExecutionInstanceInterface $instance) { return $this->incoming()->count() > 0 && $this->incoming()->find(function ($flow) use ($instance) { return $flow->origin()->getTokens($instance)->count() === 0; })->count() === 0; } /** * Action executed when the transition condition evaluates to false. * * By default a transition does not do any action if the condition is false. * * @return bool */ protected function conditionIsFalse() { return false; } /** * Do the transition of the selected tokens. * * @param CollectionInterface $consumeTokens * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $executionInstance * * @return bool */ protected function doTransit(CollectionInterface $consumeTokens, ExecutionInstanceInterface $executionInstance) { if ($this instanceof ConditionedExclusiveTransition || $this instanceof DefaultTransition) { $source = $this->outgoing()->item(0)->origin()->getOwner(); $target = $this->outgoing->item(0)->target()->getOwner(); // Find the flow that has the corresponding flow/source $flow = $source->getOutgoingFlows()->findFirst(function ($flowElement) use ($target) { return $flowElement->getTarget() === $target; }); $this->notifyConditionedTransition(TransitionInterface::EVENT_CONDITIONED_TRANSITION, $this, $flow, $executionInstance); } $this->notifyEvent(TransitionInterface::EVENT_BEFORE_TRANSIT, $this, $consumeTokens); $consumedTokensCount = $consumeTokens->count(); $consumeTokens->find(function (TokenInterface $token) use ($executionInstance) { $token->getOwner()->consumeToken($token, $executionInstance); }); $this->notifyEvent(TransitionInterface::EVENT_AFTER_CONSUME, $this, $consumeTokens); $this->outgoing()->find(function (ConnectionInterface $flow) use ($consumeTokens, $executionInstance, $consumedTokensCount) { if ($this->preserveToken && $consumedTokensCount == 1) { $consumeTokens->find(function (TokenInterface $token) use ($flow, $executionInstance) { $flow->targetState()->addToken($executionInstance, $token, false, $this); $this->onTokenTransit($token); }); } elseif ($this->preserveToken && ($token = $this->mergeTokens($consumeTokens))) { $flow->targetState()->addToken($executionInstance, $token, false, $this); $this->onTokenTransit($token); } else { $this->activateNextState($flow, $executionInstance, $consumeTokens, [], $this); } }); $this->notifyEvent(TransitionInterface::EVENT_AFTER_TRANSIT, $this, $consumeTokens); return true; } /** * Notify in the bus that a conditioned transition has been activated * * @param mixed $event * @param mixed ...$arguments */ protected function notifyConditionedTransition($event, ...$arguments) { $this->getOwner()->getOwnerProcess()->getDispatcher()->dispatch($event, $arguments); array_unshift($arguments, $event); } /** * Evaluate and execute the transition rule. * * @param ExecutionInstanceInterface $executionInstance * * @return bool */ public function execute(ExecutionInstanceInterface $executionInstance) { $hasAllRequiredTokens = $this->hasAllRequiredTokens($executionInstance); if ($hasAllRequiredTokens) { $consumeTokens = $this->evaluateConsumeTokens($executionInstance); if ($consumeTokens === false) { return $this->conditionIsFalse($executionInstance); } else { return $this->doTransit($consumeTokens, $executionInstance); } } return false; } /** * Evaluate the conditions to obtain the tokens that meet the transition condition. * * Returns false if the condition evaluates to false. * * @param ExecutionInstanceInterface $executionInstance * * @return bool|\ProcessMaker\Nayra\Bpmn\Collection */ protected function evaluateConsumeTokens(ExecutionInstanceInterface $executionInstance) { $consumeTokens = []; $hasInputTokens = false; $pendingTokens = $this->getTokensConsumedPerTransition(); $this->incoming()->find(function ($flow) use (&$consumeTokens, &$hasInputTokens, $executionInstance, &$pendingTokens) { $pendingIncomingTokens = $this->getTokensConsumedPerIncoming(); $flow->origin()->getTokens($executionInstance)->find(function (TokenInterface $token) use (&$consumeTokens, &$hasInputTokens, $executionInstance, &$pendingIncomingTokens, &$pendingTokens) { $hasInputTokens = true; $result = $pendingTokens !== 0 && $pendingIncomingTokens !== 0 && $this->assertCondition($token, $executionInstance); if ($result) { $consumeTokens[] = $token; $pendingIncomingTokens--; $pendingTokens--; } }); }); if ($consumeTokens || (!$hasInputTokens && $this->assertCondition(null, $executionInstance))) { return new Collection($consumeTokens); } else { return false; } } /** * Set the number of tokens to be consumed when a transition is activated. * * @param int $tokensConsumedPerTransition * * @return $this */ protected function setTokensConsumedPerTransition($tokensConsumedPerTransition) { $this->tokensConsumedPerTransition = $tokensConsumedPerTransition; return $this; } /** * Get the number of tokens to be consumed when a transition is activated. * * @return int */ protected function getTokensConsumedPerTransition() { return $this->tokensConsumedPerTransition; } /** * Set the number of tokens that will be consumed per incoming when a transition is activated. * * @param int $tokensConsumedPerIncoming * * @return $this */ protected function setTokensConsumedPerIncoming($tokensConsumedPerIncoming) { $this->tokensConsumedPerIncoming = $tokensConsumedPerIncoming; return $this; } /** * Get the number of tokens that will be consumed per incoming when a transition is activated. * * @return int */ protected function getTokensConsumedPerIncoming() { return $this->tokensConsumedPerIncoming; } /** * @param bool $preserveToken */ protected function setPreserveToken($preserveToken) { $this->preserveToken = $preserveToken; } /** * Get transition owner element * * @return FlowElementInterface */ public function getOwner() { return $this->owner; } /** * Activate the next state. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\ConnectionInterface $flow * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $instance * @param \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface $consumeTokens * @param array $properties * @param \ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface|null $source * * @return TokenInterface */ protected function activateNextState(ConnectionInterface $flow, ExecutionInstanceInterface $instance, CollectionInterface $consumeTokens, array $properties = [], TransitionInterface $source = null) { $token = $flow->targetState()->addNewToken($instance, $properties, $source); $this->onTokenTransit($token); } /** * When a token transit. * * @param TokenInterface $token */ protected function onTokenTransit(TokenInterface $token) { } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/BpmnEventsTrait.php
src/ProcessMaker/Nayra/Bpmn/BpmnEventsTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ReflectionClass; /** * Trait to implements bpmn events handling. */ trait BpmnEventsTrait { use ObservableTrait { notifyEvent as private internalNotifyEvent; } /** * Array map of custom event classes for the bpmn element. * * @return array */ abstract protected function getBpmnEventClasses(); /** * Fire a event for the bpmn element. * * @param string $event * @param array ...$arguments */ protected function notifyEvent($event, ...$arguments) { $bpmnEvents = $this->getBpmnEventClasses(); if (isset($bpmnEvents[$event])) { $reflector = new ReflectionClass($bpmnEvents[$event]); $payload = $reflector->newInstanceArgs($arguments); } else { $payload = $arguments; } $this->getOwnerProcess()->getDispatcher()->dispatch($event, $payload); array_unshift($arguments, $event); call_user_func_array([$this, 'internalNotifyEvent'], $arguments); call_user_func_array([$this->getOwnerProcess(), 'notifyEvent'], $arguments); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ForceGatewayTransitionTrait.php
src/ProcessMaker/Nayra/Bpmn/ForceGatewayTransitionTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; 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; } /** * If the condition is not met. * * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $executionInstance * * @return bool */ protected function conditionIsFalse() { $executionInstance = func_get_arg(0); $this->collect($executionInstance); return true; } /** * Consume the input tokens. * * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $executionInstance */ private function collect(ExecutionInstanceInterface $executionInstance) { return $this->incoming()->sum(function (Connection $flow) use ($executionInstance) { return $flow->origin()->getTokens($executionInstance)->sum(function (TokenInterface $token) { return $token->getOwner()->consumeToken($token) ? 1 : 0; }); }); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ConditionedExclusiveTransition.php
src/ProcessMaker/Nayra/Bpmn/ConditionedExclusiveTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ConditionedTransitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; use ProcessMaker\Nayra\Exceptions\RuntimeException; use Throwable; /** * Verify the condition to transit following the exclusive transition rules. * If not accomplished the tokens are consumed. */ class ConditionedExclusiveTransition implements TransitionInterface, ConditionedTransitionInterface { use TransitionTrait; use ForceGatewayTransitionTrait; /** * @var callable */ private $condition; /** * Condition required to transit the element. * * @param TokenInterface|null $token * @param ExecutionInstanceInterface|null $executionInstance * * @return mixed */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { try { // If debug mode is enabled, the transition is triggered only if it is selected if ($executionInstance && $this->shouldDebugTriggerThisTransition($executionInstance)) { return true; } // If debug mode is enabled, the transition is not triggered if it is not selected if ($executionInstance && $this->shouldDebugSkipThisTransition($executionInstance)) { return false; } $result = false; $myIndex = $this->owner->getConditionedTransitions()->indexOf($this); $condition = $this->condition; $dataStore = $executionInstance ? $executionInstance->getDataStore() : $this->getOwnerProcess()->getEngine()->getDataStore(); $myCondition = $condition($dataStore->getData()); $firstIndexTrue = $myIndex; if ($myCondition) { //find the first condition that evaluates to true foreach ($this->owner->getConditionedTransitions() as $index => $transition) { if ($index >= $myIndex) { break; } if ($transition->assertCondition($token, $executionInstance)) { $firstIndexTrue = $index; break; } } //the transition will be executed just if this transition is the first one of all transitions that are //evaluated to true. $result = $myIndex === $firstIndexTrue; } return $result; } catch (Throwable $exception) { throw new RuntimeException($exception->getMessage(), $exception->getCode(), null, $this->owner); } } /** * Set the transit condition. * * @param callable $condition * * @return $this */ public function setCondition(callable $condition) { $this->condition = $condition; return $this; } /** * If the condition is not met. * * @param ExecutionInstanceInterface $executionInstance * * @return bool */ protected function conditionIsFalse(ExecutionInstanceInterface $executionInstance) { $this->collect($executionInstance); return true; } /** * Consume the input tokens. * * @param ExecutionInstanceInterface $executionInstance * * @return int */ private function collect(ExecutionInstanceInterface $executionInstance) { return $this->incoming()->sum(function (Connection $flow) use ($executionInstance) { return $flow->origin()->getTokens($executionInstance)->sum(function (TokenInterface $token) { return $token->getOwner()->consumeToken($token) ? 1 : 0; }); }); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ThrowEventTrait.php
src/ProcessMaker/Nayra/Bpmn/ThrowEventTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ThrowEventInterface; /** * Implementation of the behavior for a throw event. */ trait ThrowEventTrait { use FlowNodeTrait; /** * Initialize catch event. */ protected function initCatchEventTrait() { $this->setProperty(ThrowEventInterface::BPMN_PROPERTY_EVENT_DEFINITIONS, new Collection); } /** * Get the event definitions. * * @return EventDefinitionInterface[] */ public function getEventDefinitions() { return $this->getProperty(ThrowEventInterface::BPMN_PROPERTY_EVENT_DEFINITIONS); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/TerminateTransition.php
src/ProcessMaker/Nayra/Bpmn/TerminateTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition rule to consume tokens in an Terminate Event. */ class TerminateTransition implements TransitionInterface { use TransitionTrait { doTransit as doTransitTrait; } /** * @var \ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface */ private $eventDefinition; /** * Condition required to terminate the token. * * @param TokenInterface|null $token * @param ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { return $this->eventDefinition->assertsRule($this->eventDefinition, $this->owner, $executionInstance); } /** * @param CollectionInterface $consumeTokens * @param ExecutionInstanceInterface $executionInstance * * @return bool */ protected function doTransit(CollectionInterface $consumeTokens, ExecutionInstanceInterface $executionInstance) { // Terminate events must close all active tokens foreach ($executionInstance->getTokens() as $token) { if ($this->assertCondition($token, $executionInstance)) { $this->eventDefinition->execute($this->eventDefinition, $this->owner, $executionInstance, $token); $token->setStatus('CLOSED'); } } return $this->doTransitTrait($consumeTokens, $executionInstance); } /** * Set the event definition that terminates the process. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface $eventDefinition */ public function setEventDefinition(EventDefinitionInterface $eventDefinition) { $this->eventDefinition = $eventDefinition; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/LoopCharacteristicsTransition.php
src/ProcessMaker/Nayra/Bpmn/LoopCharacteristicsTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ConnectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition rule that always pass the token. */ class LoopCharacteristicsTransition implements TransitionInterface { use TransitionTrait; /** * Condition required to transit the element. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface|null $token * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { $loop = $this->getOwner()->getLoopCharacteristics(); return $loop && $loop->isExecutable() && $loop->continueLoop($executionInstance, $token); } /** * Get transition owner element * * @return ActivityInterface */ public function getOwner() { return $this->owner; } /** * Activate the next state. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\ConnectionInterface $flow * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $instance * @param \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface $consumeTokens * @param array $properties * @param \ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface|null $source * * @return TokenInterface */ protected function activateNextState(ConnectionInterface $flow, ExecutionInstanceInterface $instance, CollectionInterface $consumeTokens, array $properties = [], TransitionInterface $source = null) { $nextState = $flow->targetState(); $loop = $this->getOwner()->getLoopCharacteristics(); $loop->iterateNextState($nextState, $instance, $consumeTokens, $properties, $source); } /** * Should close tokens after each loop? * * @return bool */ public function shouldCloseTokens() { $loop = $this->getOwner()->getLoopCharacteristics(); return $loop && $loop->isExecutable() && $loop->shouldCloseTokensEachLoop(); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/FormalExpressionTrait.php
src/ProcessMaker/Nayra/Bpmn/FormalExpressionTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use DateInterval; use DateTime; use Exception; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Bpmn\Models\DatePeriod; use ProcessMaker\Nayra\Contracts\Bpmn\FormalExpressionInterface; /** * Formal expression base trait. * * Include timer expressions. */ trait FormalExpressionTrait { use BaseTrait; /** * Get a DateTime if the expression is a date. * * @return \DateTime */ protected function getDateExpression() { $expression = $this->getProperty(FormalExpressionInterface::BPMN_PROPERTY_BODY); $regexpValidDate = '/^[0-9]{4}-[0-9]{2}-[0-9]{2}[T ][0-9]{2}:[0-9]{2}(:[0-9]{2})?(?:[\+-][0-9]{2}:[0-9]{2}|Z)?/'; if (preg_match($regexpValidDate, $expression)) { $date = new DateTime($expression); return $date; } else { return null; } } /** * Get a DatePeriod if the expression is a cycle. * * Ex. R4/2018-05-01T00:00:00Z/PT1M * R/2018-05-01T00:00:00Z/PT1M/2025-10-02T00:00:00Z * * @return DatePeriod */ protected function getCycleExpression() { $expression = $this->getProperty(FormalExpressionInterface::BPMN_PROPERTY_BODY); try { //Improve Repeating intervals (R/start/interval/end) configuration if (preg_match('/^R\/([^\/]+)\/([^\/]+)\/([^\/]+)$/', $expression, $repeating)) { $cycle = new DatePeriod(new DateTime($repeating[1]), new DateInterval($repeating[2]), new DateTime($repeating[3])); } else { $cycle = new DatePeriod($expression); } } catch (Exception $e) { $cycle = false; } return $cycle; } /** * Get a DateInterval if the expression is a duration. * * @return \DateInterval */ protected function getDurationExpression() { $expression = $this->getProperty(FormalExpressionInterface::BPMN_PROPERTY_BODY); try { $duration = new DateInterval($expression); } catch (Exception $e) { $duration = false; } return $duration; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/TokenTrait.php
src/ProcessMaker/Nayra/Bpmn/TokenTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\FlowElementInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StateInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; use Throwable; /** * Trait for a token. */ trait TokenTrait { use BaseTrait; /** * @var StateInterface */ private $owner; /** * @var \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface */ private $instance; /** * Get the owner of the token. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\StateInterface */ public function getOwner() { return $this->owner; } /** * Get the owner of the token. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\StateInterface $owner * * @return StateInterface */ public function setOwner(StateInterface $owner) { $this->owner = $owner; return $this; } /** * Get owner status for the current token. * * @return string */ public function getOwnerStatus() { return $this->getOwner()->getName(); } /** * Set the owner execution instance of the token. * * @param ExecutionInstanceInterface|null $instance * * @return $this */ public function setInstance(ExecutionInstanceInterface $instance = null) { $this->instance = $instance; return $this; } /** * Get the owner execution instance of the token. * * @return ExecutionInstanceInterface $instance */ public function getInstance() { return $this->instance; } /** * Get token internal status. * * @return string */ public function getStatus() { return $this->getProperty(TokenInterface::BPMN_PROPERTY_STATUS); } /** * Set token internal status. * * @param string $status * * @return $this */ public function setStatus($status) { $this->setProperty(TokenInterface::BPMN_PROPERTY_STATUS, $status); return $this; } /** * Get token internal index. * * @return index */ public function getIndex() { return $this->getProperty(TokenInterface::BPMN_PROPERTY_INDEX, 0); } /** * Set token internal index. * * @param int $index * * @return $this */ public function setIndex($index) { $this->setProperty(TokenInterface::BPMN_PROPERTY_INDEX, $index); return $this; } /** * Get the owner element of the token. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface */ public function getOwnerElement() { return $this->getOwner()->getOwner(); } /** * Log an error when executing the token * * @param \Throwable $error * @param \ProcessMaker\Nayra\Contracts\Bpmn\FlowElementInterface $bpmnElement */ public function logError(Throwable $error, FlowElementInterface $bpmnElement) { throw $error; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/ExclusiveGatewayTransition.php
src/ProcessMaker/Nayra/Bpmn/ExclusiveGatewayTransition.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Transition rule for a inclusive gateway. */ class ExclusiveGatewayTransition implements TransitionInterface { use TransitionTrait; use PauseOnGatewayTransitionTrait; /** * Initialize the tokens consumed property, the Exclusive Gateway consumes * exactly one token from each transition. */ protected function initExclusiveGatewayTransition() { $this->setTokensConsumedPerTransition(1); $this->setTokensConsumedPerIncoming(1); } /** * Always true because any token that arrives triggers the gateway * outgoing flow transition. * * @param TokenInterface|null $token * @param ExecutionInstanceInterface|null $executionInstance * * @return bool */ public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) { // Execution is paused if Engine is in demo mode and the gateway choose is not selected return !$this->shouldPauseGatewayTransition($executionInstance); } /** * In this gateway, one token should arrive, and every time this happens the gateway is ready to be triggered * * @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $executionInstance * * @return bool */ protected function hasAllRequiredTokens(ExecutionInstanceInterface $executionInstance) { if ($this->doesDemoHasAllRequiredTokens($executionInstance)) { return true; } $withToken = $this->incoming()->find(function (Connection $flow) use ($executionInstance) { return $flow->originState()->getTokens($executionInstance)->count() > 0; }); return $withToken->count() > 0; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/InclusiveGatewayTrait.php
src/ProcessMaker/Nayra/Bpmn/InclusiveGatewayTrait.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface; use ProcessMaker\Nayra\Contracts\Bpmn\GatewayInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StateInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; /** * Base implementation for a inclusive gateway. */ trait InclusiveGatewayTrait { use ConditionedGatewayTrait; /** * @var TransitionInterface */ private $transition; /** * Build the transitions that define the element. * * @param RepositoryInterface $factory */ public function buildTransitions(RepositoryInterface $factory) { $this->setRepository($factory); $this->transition = new InclusiveGatewayTransition($this); $this->transition->attachEvent(TransitionInterface::EVENT_BEFORE_TRANSIT, function () { $this->notifyEvent(GatewayInterface::EVENT_GATEWAY_ACTIVATED, $this); }); } /** * Get an input to the element. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface|null $targetFlow * * @return StateInterface */ public function getInputPlace(FlowInterface $targetFlow = null) { $incomingPlace = new State($this, GatewayInterface::TOKEN_STATE_INCOMING); $incomingPlace->connectTo($this->transition); $incomingPlace->attachEvent(State::EVENT_TOKEN_ARRIVED, function (TokenInterface $token) { $this->getRepository() ->getTokenRepository() ->persistGatewayTokenArrives($this, $token); $this->notifyEvent(GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES, $this, $token); }); $incomingPlace->attachEvent(State::EVENT_TOKEN_CONSUMED, function (TokenInterface $token) { $this->getRepository() ->getTokenRepository() ->persistGatewayTokenConsumed($this, $token); $this->notifyEvent(GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED, $this, $token); }); return $incomingPlace; } /** * Create a connection to a target node. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface $targetFlow * * @return $this */ protected function buildConnectionTo(FlowInterface $targetFlow) { return $this->buildConditionedConnectionTo($targetFlow, function () { return true; }, false); } /** * Add a conditioned transition for the inclusive gateway. * * @param FlowInterface $targetFlow * @param callable $condition * @param bool $default * * @return $this */ protected function buildConditionedConnectionTo(FlowInterface $targetFlow, callable $condition, $default = false) { $outgoingPlace = new State($this, GatewayInterface::TOKEN_STATE_OUTGOING); if ($default) { $outgoingTransition = $this->setDefaultTransition(new DefaultTransition($this)); } else { $outgoingTransition = $this->conditionedTransition( new ConditionedTransition($this), $condition ); } $outgoingTransition->attachEvent(TransitionInterface::EVENT_AFTER_CONSUME, function (TransitionInterface $transition, Collection $consumedTokens) { foreach ($consumedTokens as $token) { $this->getRepository() ->getTokenRepository() ->persistGatewayTokenPassed($this, $token); } $this->notifyEvent(GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED, $this, $transition, $consumedTokens); }); $this->transition->connectTo($outgoingPlace); $outgoingPlace->connectTo($outgoingTransition); $outgoingTransition->connectTo($targetFlow->getTarget()->getInputPlace($targetFlow)); return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/LaneSet.php
src/ProcessMaker/Nayra/Bpmn/LaneSet.php
<?php namespace ProcessMaker\Nayra\Bpmn; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\LaneSetInterface; /** * LaneSet class */ class LaneSet implements LaneSetInterface { use BaseTrait; /** * Initialize the lane set. */ protected function initLaneSet() { $this->setLanes(new Collection); } /** * Get the name of the lane set. * * @return string */ public function getName() { return $this->getProperty(self::BPMN_PROPERTY_NAME); } /** * Get the lanes of the lane set. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface */ public function getLanes() { return $this->getProperty(self::BPMN_PROPERTY_LANE); } /** * Set the name of the lane set. * * @param string $name * * @return $this */ public function setName($name) { return $this->setProperty(self::BPMN_PROPERTY_NAME, $name); } /** * Set the lanes of the lane set. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface $lanes * * @return $this */ public function setLanes(CollectionInterface $lanes) { return $this->setProperty(self::BPMN_PROPERTY_LANE, $lanes); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/TerminateEventDefinition.php
src/ProcessMaker/Nayra/Bpmn/Models/TerminateEventDefinition.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\EventDefinitionTrait; use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TerminateEventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * TerminateEventDefinition class */ class TerminateEventDefinition implements TerminateEventDefinitionInterface { use EventDefinitionTrait; /** * Assert the event definition rule for trigger the event. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return bool */ public function assertsRule(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { return true; } /** * Implement the event definition behavior when an event is triggered. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return $this */ public function execute(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Process.php
src/ProcessMaker/Nayra/Bpmn/Models/Process.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\Events\ProcessInstanceCompletedEvent; use ProcessMaker\Nayra\Bpmn\Events\ProcessInstanceCreatedEvent; use ProcessMaker\Nayra\Bpmn\Models\ActivityCollection; use ProcessMaker\Nayra\Bpmn\Models\ArtifactCollection; use ProcessMaker\Nayra\Bpmn\Models\DataStoreCollection; use ProcessMaker\Nayra\Bpmn\Models\EventCollection; use ProcessMaker\Nayra\Bpmn\Models\FlowCollection; use ProcessMaker\Nayra\Bpmn\Models\GatewayCollection; use ProcessMaker\Nayra\Bpmn\ProcessTrait; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; /** * Process implementation */ class Process implements ProcessInterface { use ProcessTrait; /** * Process constructor. * * @param array ...$args */ public function __construct(...$args) { $this->bootElement($args); $this->setActivities(new ActivityCollection); $this->setGateways(new GatewayCollection); $this->setEvents(new EventCollection); $this->setFlows(new FlowCollection); $this->setArtifacts(new ArtifactCollection); $this->setDataStores(new DataStoreCollection); } /** * Get BPMN event classes. * * @return array */ protected function getBpmnEventClasses() { return [ static::EVENT_PROCESS_INSTANCE_COMPLETED => ProcessInstanceCompletedEvent::class, static::EVENT_PROCESS_INSTANCE_CREATED => ProcessInstanceCreatedEvent::class, ]; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Token.php
src/ProcessMaker/Nayra/Bpmn/Models/Token.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\TokenTrait; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; /** * Token implementation. */ class Token implements TokenInterface { use TokenTrait; /** * Initialize a token class with unique id. */ protected function initToken() { $this->setId(uniqid()); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/SignalEventDefinition.php
src/ProcessMaker/Nayra/Bpmn/Models/SignalEventDefinition.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\EventDefinitionTrait; use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\SignalEventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\SignalInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * SignalEventDefinition class */ class SignalEventDefinition implements SignalEventDefinitionInterface { use EventDefinitionTrait; /** * @var string */ private $id; /** * Returns the element's id * * @return mixed */ public function getId() { return $this->id; } /** * Sets the element id * * @param mixed $value * * @return $this */ public function setId($value) { $this->id = $value; return $this; } /** * Sets the signal used in the signal event definition * * @param SignalInterface $value */ public function setPayload($value) { $this->setProperty(SignalEventDefinitionInterface::BPMN_PROPERTY_SIGNAL, $value); } /** * Returns the signal of the signal event definition * @return mixed */ public function getPayload() { return $this->getProperty(SignalEventDefinitionInterface::BPMN_PROPERTY_SIGNAL); } /** * Assert the event definition rule for trigger the event. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return bool */ public function assertsRule(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { return true; } /** * Implement the event definition behavior when an event is triggered. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return $this */ public function execute(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { return $this; } /** * Check if the $eventDefinition should be catch * * @param EventDefinitionInterface $eventDefinition * * @return bool */ public function shouldCatchEventDefinition(EventDefinitionInterface $eventDefinition) { $targetPayloadId = $this->getPayload() ? $this->getPayload()->getId() : $this->getProperty(SignalEventDefinitionInterface::BPMN_PROPERTY_SIGNAL_REF); $sourcePayloadId = $eventDefinition->getPayload() ? $eventDefinition->getPayload()->getId() : $eventDefinition->getProperty(SignalEventDefinitionInterface::BPMN_PROPERTY_SIGNAL_REF); return $targetPayloadId && $sourcePayloadId && $targetPayloadId === $sourcePayloadId; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/InputSet.php
src/ProcessMaker/Nayra/Bpmn/Models/InputSet.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\InputSetInterface; /** * An InputSet is a collection of DataInput elements that together define a * valid set of data inputs */ class InputSet implements InputSetInterface { use BaseTrait; /** * Initialize input set. */ protected function initInputSet() { $this->setDataInputs(new Collection); } /** * Get the DataInput elements that collectively make up this data requirement. * * @return DataInputInterface[] */ public function getDataInputs() { return $this->getProperty(static::BPMN_PROPERTY_DATA_INPUTS); } /** * Set the DataInput elements that collectively make up this data requirement. * * @param CollectionInterface $dataInputs * * @return $this */ public function setDataInputs(CollectionInterface $dataInputs) { return $this->setProperty(static::BPMN_PROPERTY_DATA_INPUTS, $dataInputs); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Operation.php
src/ProcessMaker/Nayra/Bpmn/Models/Operation.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\MessageInterface; use ProcessMaker\Nayra\Contracts\Bpmn\OperationInterface; /** * Implementation of the operation class. */ class Operation implements OperationInterface { use BaseTrait; /** * This attribute allows to reference a concrete artifact in the underlying * implementation technology representing that operation. * * @return callable */ public function getImplementation() { return $this->getProperty(OperationInterface::BPMN_PROPERTY_IMPLEMENTATION); } /** * Get the input Message of the Operation. * * @return MessageInterface */ public function getInMessage() { return $this->getProperty(OperationInterface::BPMN_PROPERTY_IN_MESSAGE); } /** * Get the output Message of the Operation. * * @return MessageInterface */ public function getOutMessage() { return $this->getProperty(OperationInterface::BPMN_PROPERTY_OUT_MESSAGE); } /** * Get errors that the Operation may return. * * @return mixed[] */ public function getErrors() { return $this->getProperty(OperationInterface::BPMN_PROPERTY_ERRORS, new Collection); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/EventCollection.php
src/ProcessMaker/Nayra/Bpmn/Models/EventCollection.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\EventCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventInterface; /** * Event Collection */ class EventCollection extends Collection implements EventCollectionInterface { /** * Add an element to the collection. * * @param EventInterface $element * * @return $this */ public function add(EventInterface $element) { $this->push($element); return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/InputOutputSpecification.php
src/ProcessMaker/Nayra/Bpmn/Models/InputOutputSpecification.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\FlowElementTrait; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\InputOutputSpecificationInterface; use ProcessMaker\Nayra\Contracts\Bpmn\InputSetInterface; use ProcessMaker\Nayra\Contracts\Bpmn\OutputSetInterface; /** * InputOutputSpecification implementation. */ class InputOutputSpecification implements InputOutputSpecificationInterface { use FlowElementTrait; /** * @return CollectionInterface */ public function getDataOutput() { return $this->getProperty(self::BPMN_PROPERTY_DATA_OUTPUT); } /** * @param CollectionInterface $dataOutput * * @return static */ public function setDataOutput(CollectionInterface $dataOutput) { return $this->setProperty(self::BPMN_PROPERTY_DATA_OUTPUT, $dataOutput); } /** * @return CollectionInterface */ public function getDataInput() { return $this->getProperty(self::BPMN_PROPERTY_DATA_INPUT); } /** * @param CollectionInterface $dataInput * * @return static */ public function setDataInput(CollectionInterface $dataInput) { return $this->setProperty(self::BPMN_PROPERTY_DATA_INPUT, $dataInput); } /** * @return InputSetInterface */ public function getInputSet() { return $this->getProperty(self::BPMN_PROPERTY_DATA_INPUT_SET); } /** * @param InputSetInterface $inputSet * * @return static */ public function setInputSet(InputSetInterface $inputSet) { return $this->setProperty(self::BPMN_PROPERTY_DATA_INPUT_SET, $inputSet); } /** * @return OutputSetInterface */ public function getOutputSet() { return $this->getProperty(self::BPMN_PROPERTY_DATA_OUTPUT_SET); } /** * @param OutputSetInterface $outputSet * * @return static */ public function setOutputSet(OutputSetInterface $outputSet) { return $this->setProperty(self::BPMN_PROPERTY_DATA_OUTPUT_SET, $outputSet); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/DataInput.php
src/ProcessMaker/Nayra/Bpmn/Models/DataInput.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\FlowElementTrait; use ProcessMaker\Nayra\Contracts\Bpmn\DataInputInterface; /** * A Data Input is a declaration that a particular kind of data will be used as * input of the InputOutputSpecification. */ class DataInput implements DataInputInterface { use FlowElementTrait; /** * Get the item subject. * * @return mixed */ public function getItemSubject() { return $this->getProperty(static::BPMN_PROPERTY_ITEM_SUBJECT); } /** * Get true is the data input is a collection. * * @return bool */ public function isCollection() { return $this->getProperty(static::BPMN_PROPERTY_IS_COLLECTION); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/ActivityCollection.php
src/ProcessMaker/Nayra/Bpmn/Models/ActivityCollection.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; /** * ActivityCollection */ class ActivityCollection extends Collection implements ActivityCollectionInterface { /** * Add an activity to the collection. * * @param ActivityInterface $element * * @return $this */ public function add(ActivityInterface $element) { $this->push($element); return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/GatewayCollection.php
src/ProcessMaker/Nayra/Bpmn/Models/GatewayCollection.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\GatewayCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\GatewayInterface; /** * Gateway Collection */ class GatewayCollection extends Collection implements GatewayCollectionInterface { /** * Add an element to the collection. * * @param GatewayInterface $element * * @return $this */ public function add(GatewayInterface $element) { $this->push($element); return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/MessageFlow.php
src/ProcessMaker/Nayra/Bpmn/Models/MessageFlow.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\MessageFlowTrait; use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CollaborationInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageFlowInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ThrowEventInterface; /** * End event implementation. */ class MessageFlow implements MessageFlowInterface { use MessageFlowTrait; private $message; /** * Get message * * @return MessageInterface */ public function getMessage() { return $this->message; } /** * Set message. * * @param MessageInterface $value */ public function setMessage(MessageInterface $value) { $this->message = $value; } /** * Source of the message. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\FlowElementInterface */ public function getSource() { return $this->getProperty(static::BPMN_PROPERTY_SOURCE); } /** * Target of the message. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\FlowElementInterface */ public function getTarget() { return $this->getProperty(static::BPMN_PROPERTY_TARGET); } /** * Set the source. * * @param ThrowEventInterface $source * * @return $this */ public function setSource($source) { return $this->setProperty(static::BPMN_PROPERTY_SOURCE, $source); } /** * Set the target. * * @param CatchEventInterface $target * * @return $this */ public function setTarget($target) { return $this->setProperty(static::BPMN_PROPERTY_TARGET, $target); } /** * Sets the collaboration of this element * * @param CollaborationInterface $collaboration * * @return $this */ public function setCollaboration(CollaborationInterface $collaboration) { return $this->setProperty(static::BPMN_PROPERTY_COLLABORATION, $collaboration); } /** * Returns the collaboration of this element * * @return CollaborationInterface */ public function getCollaboration() { return $this->getProperty(static::BPMN_PROPERTY_COLLABORATION); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Signal.php
src/ProcessMaker/Nayra/Bpmn/Models/Signal.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Contracts\Bpmn\MessageFlowInterface; use ProcessMaker\Nayra\Contracts\Bpmn\SignalInterface; /** * Implementation of signal class. */ class Signal implements SignalInterface { use BaseTrait; /** * @var string */ private $id; /** * @var string */ private $name; /** @var MessageFlowInterface */ private $messageFlow; /** * Returns the id of the message * * @return string */ public function getId() { return $this->id; } /** * Sets the id of the message * @param string $value */ public function setId($value) { $this->id = $value; } /** * Returns the name of the message * * @return string */ public function getName() { return $this->name; } /** * Sets the name of the signal * * @param string $value */ public function setName($value) { $this->name = $value; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/FlowCollection.php
src/ProcessMaker/Nayra/Bpmn/Models/FlowCollection.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\FlowCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface; /** * Collection of flows. */ class FlowCollection extends Collection implements FlowCollectionInterface { /** * Add an element to the collection. * * @param FlowInterface $element * * @return $this */ public function add(FlowInterface $element) { $this->push($element); return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/EventBasedGateway.php
src/ProcessMaker/Nayra/Bpmn/Models/EventBasedGateway.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\EventBasedGatewayTrait; use ProcessMaker\Nayra\Contracts\Bpmn\EventBasedGatewayInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; use ProcessMaker\Nayra\Exceptions\InvalidSequenceFlowException; /** * Event Based Gateway * * The Event-Based Gateway represents a branching point in the Process * where the alternative paths that follow the Gateway are based on * Events that occur, rather than the evaluation of Expressions using * Process data */ class EventBasedGateway implements EventBasedGatewayInterface { use EventBasedGatewayTrait; /** * For gateway connections. * * @param FlowNodeInterface $target * @param callable $condition * @param bool $isDefault * @param RepositoryInterface $factory * * @return $this */ public function createConditionedFlowTo( FlowNodeInterface $target, callable $condition, $isDefault, RepositoryInterface $factory ) { throw new InvalidSequenceFlowException('A parallel gateway can not have conditioned outgoing flows.'); } /** * Array map of custom event classes for the bpmn element. * * @return array */ protected function getBpmnEventClasses() { return []; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/TimerEventDefinition.php
src/ProcessMaker/Nayra/Bpmn/Models/TimerEventDefinition.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\EventDefinitionTrait; use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowElementInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TimerEventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\EngineInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; use ProcessMaker\Nayra\Contracts\Engine\JobManagerInterface; /** * MessageEventDefinition class */ class TimerEventDefinition implements TimerEventDefinitionInterface { use EventDefinitionTrait; /** * Get the date expression for the timer event definition. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\FormalExpressionInterface */ public function getTimeDate() { return $this->getProperty(self::BPMN_PROPERTY_TIME_DATE); } /** * Get the cycle expression for the timer event definition. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\FormalExpressionInterface */ public function getTimeCycle() { return $this->getProperty(self::BPMN_PROPERTY_TIME_CYCLE); } /** * Get the duration expression for the timer event definition. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\FormalExpressionInterface * * @codeCoverageIgnore Until intermediate timer event implementation */ public function getTimeDuration() { return $this->getProperty(self::BPMN_PROPERTY_TIME_DURATION); } /** * Assert the event definition rule for trigger the event. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return bool */ public function assertsRule(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { return true; } /** * Occures when the catch event was activated * * @param EngineInterface $engine * @param CatchEventInterface $element * @param TokenInterface|null $token * * @return void */ public function catchEventActivated(EngineInterface $engine, CatchEventInterface $element, TokenInterface $token = null) { $this->scheduleTimerEvents($engine, $element, $token); } /** * Register in catch events. * * @param EngineInterface $engine * @param FlowElementInterface $element * @param TokenInterface|null $token */ public function scheduleTimerEvents(EngineInterface $engine, FlowElementInterface $element, TokenInterface $token = null) { $this->scheduleTimeDuration($engine, $element, $token); $this->scheduleTimeDate($engine, $element, $token); $this->scheduleTimeCycle($engine, $element, $token); } /** * Get the data store. * * @param EngineInterface $engine * @param TokenInterface|null $token * * @return \ProcessMaker\Nayra\Contracts\Bpmn\DataStoreInterface */ private function getDataFrom(EngineInterface $engine, TokenInterface $token = null) { $dataStore = $token ? $token->getInstance()->getDataStore() : $engine->getDataStore(); return $dataStore ? $dataStore->getData() : []; } /** * Evaluates a timer expression. * * @param callable $expression * @param array $data * * @return DateTime|DatePeriod|DateInterval */ private function evaluateTimer(callable $expression, array $data) { $value = $expression($data); if (is_string($value)) { $formal = $this->getRepository()->createFormalExpression(); $formal->setProperty('body', $value); return $formal($data); } return $value; } /** * Schedule as timeDate. * * @param EngineInterface $engine * @param FlowElementInterface $element * @param TokenInterface|null $token */ private function scheduleTimeDate(EngineInterface $engine, FlowElementInterface $element, TokenInterface $token = null) { $expression = $this->getTimeDate(); if ($expression) { $date = $this->evaluateTimer($expression, $this->getDataFrom($engine, $token)); $dates = is_array($date) ? $date : [$date]; foreach ($dates as $date) { $engine->getJobManager()->scheduleDate($date, $this, $element, $token); $engine->getDispatcher()->dispatch( JobManagerInterface::EVENT_SCHEDULE_DATE, $date, $this, $element, $token ); } } } /** * Schedule as timeDate. * * @param EngineInterface $engine * @param FlowElementInterface $element * @param TokenInterface|null $token */ private function scheduleTimeCycle(EngineInterface $engine, FlowElementInterface $element, TokenInterface $token = null) { $expression = $this->getTimeCycle(); if ($expression) { $cycle = $this->evaluateTimer($expression, $this->getDataFrom($engine, $token)); $cycles = is_array($cycle) ? $cycle : [$cycle]; foreach ($cycles as $cycle) { $engine->getJobManager()->scheduleCycle($cycle, $this, $element, $token); $engine->getDispatcher()->dispatch( JobManagerInterface::EVENT_SCHEDULE_CYCLE, $cycle, $this, $element, $token ); } } } /** * Schedule as timeDuration. * * @param EngineInterface $engine * @param FlowElementInterface $element * @param TokenInterface|null $token */ private function scheduleTimeDuration(EngineInterface $engine, FlowElementInterface $element, TokenInterface $token = null) { $expression = $this->getTimeDuration(); if ($expression) { $duration = $this->evaluateTimer($expression, $this->getDataFrom($engine, $token)); $durations = is_array($duration) ? $duration : [$duration]; foreach ($durations as $duration) { $engine->getJobManager()->scheduleDuration($duration, $this, $element, $token); $engine->getDispatcher()->dispatch( JobManagerInterface::EVENT_SCHEDULE_DURATION, $duration, $this, $element, $token ); } } } /** * Set the date expression for the timer event definition. * * @param callable $timeExpression */ public function setTimeDate(callable $timeExpression) { $this->setProperty(self::BPMN_PROPERTY_TIME_DATE, $timeExpression); } /** * Set the cycle expression for the timer event definition. * * @param callable $timeExpression */ public function setTimeCycle(callable $timeExpression) { $this->setProperty(self::BPMN_PROPERTY_TIME_CYCLE, $timeExpression); } /** * Set the duration expression for the timer event definition. * * @param callable $timeExpression */ public function setTimeDuration(callable $timeExpression) { $this->setProperty(self::BPMN_PROPERTY_TIME_DURATION, $timeExpression); } /** * Implement the event definition behavior when an event is triggered. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return $this */ public function execute(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/IntermediateThrowEvent.php
src/ProcessMaker/Nayra/Bpmn/Models/IntermediateThrowEvent.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Bpmn\IntermediateThrowEventTrait; use ProcessMaker\Nayra\Contracts\Bpmn\IntermediateThrowEventInterface; /** * IntermediateThrowEvent implementation. */ class IntermediateThrowEvent implements IntermediateThrowEventInterface { use IntermediateThrowEventTrait; /** * @var \ProcessMaker\Nayra\Contracts\Bpmn\InputSetInterface */ private $inputSet; /** * @var \ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface[] */ private $eventDefinitions; /** * Initialize intermediate throw event. */ protected function initIntermediateThrowEvent() { $this->properties[static::BPMN_PROPERTY_DATA_INPUT_ASSOCIATION] = new Collection; $this->properties[static::BPMN_PROPERTY_DATA_INPUT] = new Collection; $this->setProperty(static::BPMN_PROPERTY_EVENT_DEFINITIONS, new Collection); } /** * Get BPMN event classes. * * @return array */ protected function getBpmnEventClasses() { return []; } /** * Get data input associations. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface */ public function getDataInputAssociations() { return $this->getProperty(static::BPMN_PROPERTY_DATA_INPUT_ASSOCIATION); } /** * Get data inputs. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface */ public function getDataInputs() { return $this->getProperty(static::BPMN_PROPERTY_DATA_INPUT); } /** * Get event definitions. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface */ public function getEventDefinitions() { return $this->getProperty(static::BPMN_PROPERTY_EVENT_DEFINITIONS); } /** * Get input set. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\InputSetInterface */ public function getInputSet() { return $this->inputSet; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/DataStore.php
src/ProcessMaker/Nayra/Bpmn/Models/DataStore.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\DataStoreTrait; use ProcessMaker\Nayra\Contracts\Bpmn\DataStoreInterface; /** * Application */ class DataStore implements DataStoreInterface { use DataStoreTrait; }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Collaboration.php
src/ProcessMaker/Nayra/Bpmn/Models/Collaboration.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\CollaborationInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CorrelationKeyInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageFlowInterface; /** * Implementation of Collaboration element. */ class Collaboration implements CollaborationInterface { use BaseTrait; /** * @var bool */ private $isClosed; /** * @var CorrelationKeyInterface[] */ private $correlationKeys; /** @var Collection */ private $artifacts; /** @var Collection */ private $choreographies; /** @var Collection */ private $conversationAssociations; /** @var Collection */ private $conversationLinks; /** @var Collection */ private $conversationNodes; /** @var Collection */ private $messageFlowAssociations; /** @var Collection */ private $participantAssociations; /** * Initialize the collaboration element. */ protected function initCollaboration() { $this->artifacts = new Collection; $this->choreographies = new Collection; $this->conversationAssociations = new Collection; $this->conversationLinks = new Collection; $this->conversationNodes = new Collection; $this->correlationKeys = new Collection; $this->messageFlowAssociations = new Collection; $this->participantAssociations = new Collection; $this->setMessageFlows(new Collection); $this->setProperty(CollaborationInterface::BPMN_PROPERTY_PARTICIPANT, new Collection); } /** * Get correlation keys. * * @return CorrelationKeyInterface[] */ public function getCorrelationKeys() { return $this->correlationKeys; } /** * Get message flows. * * @return MessageFlowInterface[] */ public function getMessageFlows() { return $this->getProperty(static::BPMN_PROPERTY_MESSAGE_FLOWS); } /** * Add a message flow. * * @param MessageFlowInterface $messageFlow * * @return $this */ public function addMessageFlow(MessageFlowInterface $messageFlow) { return $this->addProperty(static::BPMN_PROPERTY_MESSAGE_FLOWS, $messageFlow); } /** * Get participants. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\ParticipantInterface[] */ public function getParticipants() { return $this->getProperty(CollaborationInterface::BPMN_PROPERTY_PARTICIPANT); } /** * Get a boolean value specifying whether Message Flows not modeled in the * Collaboration can occur when the Collaboration is carried out. * * @return bool */ public function isClosed() { return $this->isClosed; } /** * Set if the collaboration is closed. * * @param bool $isClosed * * @return $this */ public function setClosed($isClosed) { $this->isClosed = $isClosed; return $this; } /** * Set message flows collection. * * @param CollectionInterface $messageFlows * * @return $this */ public function setMessageFlows(CollectionInterface $messageFlows) { return $this->setProperty(static::BPMN_PROPERTY_MESSAGE_FLOWS, $messageFlows); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/StandardLoopCharacteristics.php
src/ProcessMaker/Nayra/Bpmn/Models/StandardLoopCharacteristics.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\StandardLoopCharacteristicsTrait; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FormalExpressionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StandardLoopCharacteristicsInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StateInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Standard implementation. */ class StandardLoopCharacteristics implements StandardLoopCharacteristicsInterface { use StandardLoopCharacteristicsTrait; /** * Check if the loop can be formally executed * * @return bool */ public function isExecutable() { $loopMaximumValid = false; $loopConditionValid = false; $loopMaximum = $this->getLoopMaximum(); $loopCondition = $this->getLoopCondition(); if ($loopMaximum) { $loopMaximumValid = true; } if ($loopCondition && $loopCondition->getBody()) { $loopConditionValid = true; } return $loopMaximumValid || $loopConditionValid; } /** * Get item of the input data collection by index * * @param ExecutionInstanceInterface $instance * @param int $index * * @return mixed */ private function getInputDataItemValue(ExecutionInstanceInterface $instance, $index) { $dataStore = $instance->getDataStore(); return $dataStore->getData(); } /** * Iterate to next active state * * @param StateInterface $nextState * @param ExecutionInstanceInterface $instance * @param CollectionInterface $consumeTokens * @param array $properties * @param TransitionInterface|null $source * * @return void */ public function iterateNextState(StateInterface $nextState, ExecutionInstanceInterface $instance, CollectionInterface $consumeTokens, array $properties = [], TransitionInterface $source = null) { foreach ($consumeTokens as $token) { $properties = $this->prepareLoopInstanceProperties($token, $properties); // LoopInstance Counter $loopCounter = $this->getLoopInstanceProperty($token, 'loopCounter', 0); // Token loopCounter $tokenLoopCounter = $token->getProperty('data', [])['loopCounter'] ?? 0; if ($loopCounter === $tokenLoopCounter) { $loopCounter++; $this->createInstance( $instance, $properties, $loopCounter, $nextState, $source ); } } } /** * @param ExecutionInstanceInterface $instance * @param array $properties * @param int $loopCounter * @param StateInterface $nextState * @param TransitionInterface $source * @return void */ private function createInstance( ExecutionInstanceInterface $instance, array $properties, $loopCounter, StateInterface $nextState, TransitionInterface $source ) { $item = $this->getInputDataItemValue($instance, $loopCounter); $properties['data'] = []; $properties['data'] = array_merge($properties['data'], (array) $item); $properties['data']['loopCounter'] = $loopCounter; $newToken = $nextState->createToken($instance, $properties, $source); $this->setLoopInstanceProperty($newToken, 'loopCounter', $loopCounter); $nextState->addToken($instance, $newToken, false, $source); } /** * @param ExecutionInstanceInterface $instance * @param TokenInterface $token * * @return bool */ public function continueLoop(ExecutionInstanceInterface $instance, TokenInterface $token) { if ($this->getTestBefore()) { return $this->checkBeforeLoop($instance, $token); } return $this->checkAfterLoop($instance, $token); } /** * @param ExecutionInstanceInterface $instance * @param TokenInterface $token * @return bool */ public function isLoopCompleted(ExecutionInstanceInterface $instance, TokenInterface $token) { if ($this->getTestBefore()) { return !$this->checkBeforeLoop($instance, $token); } return !$this->checkAfterLoop($instance, $token); } /** * Checking performed before running the loop * * @param ExecutionInstanceInterface $instance * @param TokenInterface $token * * @return bool */ private function checkBeforeLoop(ExecutionInstanceInterface $instance, TokenInterface $token) { $testBefore = $this->getTestBefore(); $condition = $this->getLoopCondition(); $data = $instance->getDataStore()->getData(); $evaluatedCondition = $condition($data); $loopMaximum = $this->getLoopMaximumFormalExpression($data); $loopCounter = $this->getLoopInstanceProperty($token, 'loopCounter', 0); $loopCondition = $loopMaximum === null || $loopMaximum === 0 || $loopCounter < $loopMaximum; if ($testBefore && $evaluatedCondition && $loopCondition) { return true; } return false; } /** * Checking performed after running the loop * * @param ExecutionInstanceInterface $instance * @param TokenInterface $token * * @return bool */ private function checkAfterLoop(ExecutionInstanceInterface $instance, TokenInterface $token) { $testBefore = $this->getTestBefore(); $condition = $this->getLoopCondition(); $data = $instance->getDataStore()->getData(); $loopMaximum = $this->getLoopMaximumFormalExpression($data); $loopCounter = $this->getLoopInstanceProperty($token, 'loopCounter', 0); $loopCondition = $loopMaximum === null || $loopCounter < $loopMaximum; if (!$testBefore && $loopCounter === 0) { return true; } if ($condition) { $exitCondition = $condition($data); if (!$testBefore && !$exitCondition && $loopCondition) { return true; } } else { if (!$testBefore && $loopCondition) { return true; } } return false; } /** * getLoopMaximumFormalExpression * * @param array $data * * @return int */ private function getLoopMaximumFormalExpression(array $data) { $expression = $this->getLoopMaximum(); $formalExpression = $this->getRepository()->createFormalExpression(); $formalExpression->setProperty(FormalExpressionInterface::BPMN_PROPERTY_BODY, $expression); return $formalExpression($data); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Flow.php
src/ProcessMaker/Nayra/Bpmn/Models/Flow.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\FlowTrait; use ProcessMaker\Nayra\Bpmn\Models\Process; use ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; /** * Flow implementation. * * * @codeCoverageIgnore */ class Flow implements FlowInterface { use FlowTrait; /** * @return FlowNodeInterface */ public function getSource() { return $this->getProperty(FlowInterface::BPMN_PROPERTY_SOURCE); } /** * @param FlowNodeInterface $source * * @return $this */ public function setSource(FlowNodeInterface $source) { $this->setProperty(FlowInterface::BPMN_PROPERTY_SOURCE, $source); return $this; } /** * @return FlowNodeInterface */ public function getTarget() { return $this->getProperty(FlowInterface::BPMN_PROPERTY_TARGET); } /** * @param FlowNodeInterface $target * * @return $this */ public function setTarget(FlowNodeInterface $target) { $this->setProperty(FlowInterface::BPMN_PROPERTY_TARGET, $target); return $this; } /** * @return callable */ public function getCondition() { return $this->getProperty(FlowInterface::BPMN_PROPERTY_CONDITION_EXPRESSION, function () { return true; }); } /** * @return bool */ public function isDefault() { return $this->getProperty(FlowInterface::BPMN_PROPERTY_IS_DEFAULT, false); } /** * @return bool */ public function hasCondition() { return $this->getProperty(FlowInterface::BPMN_PROPERTY_CONDITION_EXPRESSION, null) !== null; } /** * @var Process */ private $process; /** * Get process. * * @return Process */ public function getProcess() { return $this->process; } /** * Set the process. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface $process * @return $this */ public function setProcess(ProcessInterface $process) { $this->process = $process; return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/ErrorEventDefinition.php
src/ProcessMaker/Nayra/Bpmn/Models/ErrorEventDefinition.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\EventDefinitionTrait; use ProcessMaker\Nayra\Contracts\Bpmn\ErrorEventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ErrorInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * ErrorEventDefinition class */ class ErrorEventDefinition implements ErrorEventDefinitionInterface { use EventDefinitionTrait; /** * Assert the event definition rule to trigger the event. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return bool */ public function assertsRule(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { return true; } /** * Get the error of the event definition. * * @return ErrorInterface */ public function getError() { return $this->getProperty(ErrorEventDefinitionInterface::BPMN_PROPERTY_ERROR); } /** * Set the error of the event definition. * * @param ErrorInterface $error * * @return $this */ public function setError(ErrorInterface $error) { $this->setProperty(ErrorEventDefinitionInterface::BPMN_PROPERTY_ERROR, $error); return $this; } /** * Returns the event definition payload (message, signal, etc.) * * @return mixed */ public function getPayload() { return $this->getError(); } /** * Implement the event definition behavior when an event is triggered. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return $this */ public function execute(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { return $this; } /** * Check if the $eventDefinition should be catch * * @param EventDefinitionInterface $eventDefinition * * @return bool */ public function shouldCatchEventDefinition(EventDefinitionInterface $eventDefinition) { $targetPayloadId = $this->getPayload() ? $this->getPayload()->getId() : $this->getProperty(ErrorEventDefinitionInterface::BPMN_PROPERTY_ERROR_REF); $sourcePayloadId = $eventDefinition->getPayload() ? $eventDefinition->getPayload()->getId() : $eventDefinition->getProperty(ErrorEventDefinitionInterface::BPMN_PROPERTY_ERROR_REF); return !$targetPayloadId || ($targetPayloadId && $sourcePayloadId && $targetPayloadId === $sourcePayloadId); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Artifact.php
src/ProcessMaker/Nayra/Bpmn/Models/Artifact.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Contracts\Bpmn\ArtifactInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; /** * Class that implements the ArtifactInterface */ class Artifact implements ArtifactInterface { private $process; use BaseTrait; /** * Get the Process of the artifact. * * @return ProcessInterface */ public function getProcess() { return $this->process; } /** * Set the Process of the artifact. * * @param ProcessInterface $process * @return $this */ public function setProcess(ProcessInterface $process) { $this->process = $process; return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/ConditionalEventDefinition.php
src/ProcessMaker/Nayra/Bpmn/Models/ConditionalEventDefinition.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\EventDefinitionTrait; use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ConditionalEventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\EngineInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * ConditionalEventDefinition class */ class ConditionalEventDefinition implements ConditionalEventDefinitionInterface { use EventDefinitionTrait; /** * Assert the event definition rule for trigger the event. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return bool */ public function assertsRule(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { // Get context data if ($instance && $target instanceof CatchEventInterface) { $data = $instance->getDataStore()->getData(); $tokenCatch = $target->getActiveState()->getTokens($instance)->item(0); $conditionals = $tokenCatch->getProperty('conditionals', []); } else { $process = $target->getOwnerProcess(); $engine = $process->getEngine(); $data = $engine->getDataStore()->getData(); $conditionals = $process->getProperty('conditionals', []); } // Get previous value $key = $this->getBpmnElement()->getNodePath(); $previous = $conditionals[$key] ?? null; // Evaluate condition $condition = $this->getCondition(); // Conditional in conditional start event should be treated as false when condition is empty and // should not execute. But for Multi Instance Loops and Exclusive gateways it should be treated as // true when conditional is empty, to avoid infinite loops and allows exclusive gateways to run. $current = empty($condition->getProperties()['body']) ? false : $condition($data); // Update previous value $conditionals[$key] = $current; if ($instance && $target instanceof CatchEventInterface) { foreach ($target->getActiveState()->getTokens($instance) as $tokenCatch) { $tokenCatch->setProperty('conditionals', $conditionals); } } else { $process->setProperty('conditionals', $conditionals); } return !$previous && $current; } /** * Get the condition of the event definition. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\FormalExpressionInterface */ public function getCondition() { return $this->getProperty(ConditionalEventDefinitionInterface::BPMN_PROPERTY_CONDITION); } /** * Implement the event definition behavior when an event is triggered. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return $this */ public function execute(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { return $this; } /** * Occures when the catch event is activated * * @param EngineInterface $engine * @param CatchEventInterface $element * @param TokenInterface|null $token * * @return void */ public function catchEventActivated(EngineInterface $engine, CatchEventInterface $element, TokenInterface $token = null) { } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/EndEvent.php
src/ProcessMaker/Nayra/Bpmn/Models/EndEvent.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Bpmn\EndEventTrait; use ProcessMaker\Nayra\Contracts\Bpmn\EndEventInterface; use ProcessMaker\Nayra\Model\DataInputAssociationInterface; use ProcessMaker\Nayra\Model\DataInputInterface; use ProcessMaker\Nayra\Model\EventDefinitionInterface; use ProcessMaker\Nayra\Model\InputSetInterface; use ProcessMaker\Nayra\Model\TokenInterface; /** * Class EndEvent * * @codeCoverageIgnore */ class EndEvent implements EndEventInterface { use EndEventTrait; private $inputSet; /** * Initialize intermediate throw event. */ protected function initEndEvent() { $this->properties[static::BPMN_PROPERTY_DATA_INPUT_ASSOCIATION] = new Collection(); $this->properties[static::BPMN_PROPERTY_DATA_INPUT] = new Collection; $this->setProperty(static::BPMN_PROPERTY_EVENT_DEFINITIONS, new Collection); } /** * Array map of custom event classes for the bpmn element. * * @return array */ protected function getBpmnEventClasses() { return []; } /** * @param EventDefinitionInterface $message * @param TokenInterface $token * @return \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface[] */ public function getTargetInstances(EventDefinitionInterface $message, TokenInterface $token) { return $this->getOwnerProcess()->getInstances(); } /** * Get Data Inputs for the throw Event. * * @return DataInputInterface[] */ public function getDataInputs() { return $this->getProperty(static::BPMN_PROPERTY_DATA_INPUT); } /** * Get Data Associations of the throw Event. * * @return DataInputAssociationInterface[] */ public function getDataInputAssociations() { return $this->getProperty(static::BPMN_PROPERTY_DATA_INPUT_ASSOCIATION); } /** * Get InputSet for the throw Event. * * @return InputSetInterface */ public function getInputSet() { return $this->inputSet; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Error.php
src/ProcessMaker/Nayra/Bpmn/Models/Error.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Contracts\Bpmn\ErrorInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageFlowInterface; class Error implements ErrorInterface { use BaseTrait; /** * @var MessageFlowInterface */ private $messageFlow; /** * Returns the name of the message * * @return string */ public function getName() { return $this->getProperty(ErrorInterface::BPMN_PROPERTY_NAME); } /** * Get the error code. * * @return string */ public function getErrorCode() { return $this->getProperty(ErrorInterface::BPMN_PROPERTY_ERROR_CODE); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/ItemDefinition.php
src/ProcessMaker/Nayra/Bpmn/Models/ItemDefinition.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Contracts\Bpmn\ItemDefinitionInterface; /** * ItemDefinition class */ class ItemDefinition implements ItemDefinitionInterface { use BaseTrait; /** * Get the nature of the Item. Possible values are physical * or information. * * @return string */ public function getItemKind() { return $this->getProperty(ItemDefinitionInterface::BPMN_PROPERTY_ITEM_KIND); } /** * Get the concrete data structure to be used. * * @return mixed */ public function getStructure() { return $this->getProperty(ItemDefinitionInterface::BPMN_PROPERTY_STRUCTURE); } /** * Get true if the data structure represents a collection. * * @return bool */ public function isCollection() { return $this->getProperty(ItemDefinitionInterface::BPMN_PROPERTY_IS_COLLECTION); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/IntermediateCatchEvent.php
src/ProcessMaker/Nayra/Bpmn/Models/IntermediateCatchEvent.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\IntermediateCatchEventTrait; use ProcessMaker\Nayra\Contracts\Bpmn\IntermediateCatchEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageListenerInterface; /** * IntermediateThrowEvent implementation. */ class IntermediateCatchEvent implements IntermediateCatchEventInterface, MessageListenerInterface { use IntermediateCatchEventTrait; /** * Get BPMN event classes. * * @return array */ protected function getBpmnEventClasses() { return []; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/EventDefinitionBus.php
src/ProcessMaker/Nayra/Bpmn/Models/EventDefinitionBus.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\ObservableTrait; use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CollaborationInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StartEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\EventDefinitionBusInterface; /** * Implements a events bus for the bpmn elements. */ class EventDefinitionBus implements EventDefinitionBusInterface { use ObservableTrait; private $collaboration; /** * Dispatch an event definition * * @param mixed $source * @param EventDefinitionInterface $eventDefinition * @param TokenInterface|null $token * * @return EventDefinitionBusInterface */ public function dispatchEventDefinition($source, EventDefinitionInterface $eventDefinition, TokenInterface $token = null) { $this->notifyEvent(get_class($eventDefinition), $source, $eventDefinition, $token); return $this; } /** * Register a catch event element * * @param CatchEventInterface $catchEvent * @param EventDefinitionInterface $eventDefinition * @param callable $callable * * @return EventDefinitionBusInterface */ public function registerCatchEvent(CatchEventInterface $catchEvent, EventDefinitionInterface $eventDefinition, callable $callable) { $this->attachEvent(get_class($eventDefinition), function ($source, EventDefinitionInterface $sourceEventDefinition, TokenInterface $token = null) use ($catchEvent, $callable, $eventDefinition) { if (get_class($sourceEventDefinition) === get_class($eventDefinition)) { $match = $eventDefinition->shouldCatchEventDefinition($sourceEventDefinition); if (!$match) { return; } $targetCatch = $sourceEventDefinition->getProperty('target_catch_event_id'); if ($targetCatch && $catchEvent->getId() !== $targetCatch) { return; } if ($catchEvent instanceof StartEventInterface && $sourceEventDefinition->getDoNotTriggerStartEvents()) { return; } if ($catchEvent instanceof StartEventInterface) { $callable($eventDefinition, null, $token); } else { $instances = $this->getInstancesFor($catchEvent); foreach ($instances as $instance) { $targetInstance = $sourceEventDefinition->getProperty('target_instance_id'); if ($targetInstance && $instance->getId() !== $targetInstance) { continue; } $callable($eventDefinition, $instance, $token); } } } }); return $this; } /** * Set collaboration * * @param CollaborationInterface $collaboration * * @return EventDefinitionBusInterface */ public function setCollaboration(CollaborationInterface $collaboration) { $this->collaboration = $collaboration; return $this; } /** * Get collaboration * * @return CollaborationInterface */ public function getCollaboration() { return $this->collaboration; } /** * Get instances for a catch event * * @param CatchEventInterface $catchEvent * * @return \ProcessMaker\Nayra\Bpmn\Collection */ private function getInstancesFor(CatchEventInterface $catchEvent) { return $catchEvent->getProcess()->getInstances(); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/MultiInstanceLoopCharacteristics.php
src/ProcessMaker/Nayra/Bpmn/Models/MultiInstanceLoopCharacteristics.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use Countable; use Exception; use ProcessMaker\Nayra\Bpmn\MultiInstanceLoopCharacteristicsTrait; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\DataInputInterface; use ProcessMaker\Nayra\Contracts\Bpmn\DataStoreInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MultiInstanceLoopCharacteristicsInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StateInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Multiinstance implementation. */ class MultiInstanceLoopCharacteristics implements MultiInstanceLoopCharacteristicsInterface { use MultiInstanceLoopCharacteristicsTrait; /** * Calculate the number of intances for the MI activity * * @param ExecutionInstanceInterface $instance * * @return int */ private function calcNumberOfInstances(ExecutionInstanceInterface $instance) { $dataStore = $instance->getDataStore(); $loopCardinality = $this->getLoopCardinality(); $loopDataInput = $this->getLoopDataInput(); if ($loopCardinality) { return $loopCardinality($dataStore->getData()); } else { return count($this->getInputDataValue($loopDataInput, $dataStore)); } } /** * Check if the loop can be formally executed * * @return bool */ public function isExecutable() { $loopCardinality = $this->getLoopCardinality(); $loopDataInput = $this->getLoopDataInput(); return $loopCardinality || $loopDataInput; } /** * Get input data runtime value * * @param DataInputInterface $dataInput * @param DataStoreInterface $dataStore * * @return CollectionInterface|array */ private function getInputDataValue(DataInputInterface $dataInput, DataStoreInterface $dataStore) { $expression = $this->getRepository()->createFormalExpression(); $expression->setBody($dataInput->getName()); return $expression($dataStore->getData()); } /** * Get item of the input data collection by index * * @param ExecutionInstanceInterface $instance * @param int $index * * @return mixed */ private function getInputDataItemValue(ExecutionInstanceInterface $instance, $index) { $dataStore = $instance->getDataStore(); $dataInput = $this->getLoopDataInput(); if (!$dataInput) { return null; } return $this->getInputDataValue($dataInput, $dataStore)[$index - 1]; } /** * Get item of the output data from token * * @param TokenInterface $token * * @return array */ private function getOutputDataItemValue(TokenInterface $token) { $data = $token->getProperty('data', []); $name = $this->getOutputDataItem() ? $this->getOutputDataItem()->getName() : null; if ($name) { return $data[$name] ?? null; } return $data; } /** * Iterate to next active state * * @param StateInterface $nextState * @param ExecutionInstanceInterface $instance * @param CollectionInterface $consumeTokens * @param array $properties * @param TransitionInterface|null $source * * @return void */ public function iterateNextState(StateInterface $nextState, ExecutionInstanceInterface $instance, CollectionInterface $consumeTokens, array $properties = [], TransitionInterface $source = null) { $inputDataItem = $this->getInputDataItem() ? $this->getInputDataItem()->getName() : null; foreach ($consumeTokens as $token) { $properties = $this->prepareLoopInstanceProperties($token, $properties); // The number of instances are calculated once, when entering the activity. $numberOfInstances = $this->calcNumberOfInstances($instance); if ($this->getIsSequential()) { // LoopInstance Counter $loopCounter = $this->getLoopInstanceProperty($token, 'loopCounter', 0); // Token loopCounter $tokenLoopCounter = $token->getProperty('data', [])['loopCounter'] ?? 0; if ($loopCounter === $tokenLoopCounter && $loopCounter < $numberOfInstances) { $loopCounter++; $numberOfActiveInstances = 1; $this->createInstance( $instance, $properties, $loopCounter, $inputDataItem, $nextState, $source, $numberOfActiveInstances, $numberOfInstances ); } } else { $numberOfActiveInstances = $numberOfInstances; $newTokens = []; for ($loopCounter = 1; $loopCounter <= $numberOfInstances; $loopCounter++) { $newTokens[] = $this->createInstance( $instance, $properties, $loopCounter, $inputDataItem, $nextState, $source, $numberOfActiveInstances, $numberOfInstances, true ); } // Throw token events foreach ($newTokens as $token) { $nextState->notifyExternalEvent(StateInterface::EVENT_TOKEN_ARRIVED, $token, $source); } } } } /** * @param ExecutionInstanceInterface $instance * @param array $properties * @param int $loopCounter * @param string $inputDataItem * @param StateInterface $nextState * @param TransitionInterface $source * @param int $numberOfActiveInstances * @param int $numberOfInstances * @return TokenInterface */ private function createInstance( ExecutionInstanceInterface $instance, array $properties, $loopCounter, $inputDataItem, StateInterface $nextState, TransitionInterface $source, $numberOfActiveInstances, $numberOfInstances, $skipEvents = false ) { $item = $this->getInputDataItemValue($instance, $loopCounter); $properties['data'] = []; if ($inputDataItem) { $properties['data'][$inputDataItem] = $item; } elseif ($item) { $properties['data'] = array_merge($properties['data'], (array) $item); } $properties['data']['loopCounter'] = $loopCounter; $newToken = $nextState->createToken($instance, $properties, $source); $this->setLoopInstanceProperty($newToken, 'numberOfActiveInstances', $numberOfActiveInstances); $this->setLoopInstanceProperty($newToken, 'numberOfInstances', $numberOfInstances); $this->setLoopInstanceProperty($newToken, 'loopCounter', $loopCounter); return $nextState->addToken($instance, $newToken, $skipEvents, $source); } /** * @param ExecutionInstanceInterface $instance * @param TokenInterface $token * * @return bool */ public function continueLoop(ExecutionInstanceInterface $instance, TokenInterface $token) { $numberOfInstances = $this->getLoopInstanceProperty($token, 'numberOfInstances', 0); $active = $this->getLoopInstanceProperty($token, 'numberOfActiveInstances', 0); $completed = $this->getLoopInstanceProperty($token, 'numberOfCompletedInstances', 0); $terminated = $this->getLoopInstanceProperty($token, 'numberOfTerminatedInstances', 0); $total = $active + $completed + $terminated; return $total < $numberOfInstances; } /** * @param ExecutionInstanceInterface $instance * @param TokenInterface $token * @return bool */ public function isLoopCompleted(ExecutionInstanceInterface $instance, TokenInterface $token) { $numberOfInstances = $this->getLoopInstanceProperty($token, 'numberOfInstances', null); if ($numberOfInstances === null) { $numberOfInstances = $this->calcNumberOfInstances($instance); } $completed = $this->getLoopInstanceProperty($token, 'numberOfCompletedInstances', 0); $condition = $this->getCompletionCondition(); $hasCompletionCondition = $condition && trim($condition->getBody()); $completionCondition = false; if ($hasCompletionCondition) { $data = $this->getOutputDataItemValue($token); try { $completionCondition = $condition($data); } catch (Exception $e) { // When the condition can not be evaluated, it is considered false. $completionCondition = false; } } return $completionCondition || $completed >= $numberOfInstances; } /** * @param TokenInterface $token * * @return void */ public function onTokenCompleted(TokenInterface $token) { $numberOfActiveInstances = $this->getLoopInstanceProperty($token, 'numberOfActiveInstances', 0); $numberOfCompletedInstances = $this->getLoopInstanceProperty($token, 'numberOfCompletedInstances', 0); $numberOfActiveInstances--; $numberOfCompletedInstances++; $this->setLoopInstanceProperty($token, 'numberOfActiveInstances', $numberOfActiveInstances); $this->setLoopInstanceProperty($token, 'numberOfCompletedInstances', $numberOfCompletedInstances); } /** * @param TokenInterface $token * * @return void */ public function onTokenTerminated(TokenInterface $token) { $numberOfActiveInstances = $this->getLoopInstanceProperty($token, 'numberOfActiveInstances', 0); $numberOfTerminatedInstances = $this->getLoopInstanceProperty($token, 'numberOfTerminatedInstances', 0); $numberOfActiveInstances--; $numberOfTerminatedInstances++; $this->setLoopInstanceProperty($token, 'numberOfActiveInstances', $numberOfActiveInstances); $this->setLoopInstanceProperty($token, 'numberOfTerminatedInstances', $numberOfTerminatedInstances); } /** * Merge output data into instance data * * @param CollectionInterface $consumedTokens * @param ExecutionInstanceInterface $instance * * @return void */ public function mergeOutputData(CollectionInterface $consumedTokens, ExecutionInstanceInterface $instance) { $outputVariable = $this->getLoopDataOutput() ? $this->getLoopDataOutput()->getName() : null; if ($outputVariable) { $result = []; foreach ($consumedTokens as $token) { $result[] = $this->getOutputDataItemValue($token); } $instance->getDataStore()->putData($outputVariable, $result); } } /** * Check if data input is valid * * @param ExecutionInstanceInterface $instance * @param TokenInterface $token * * @return bool */ public function isDataInputValid(ExecutionInstanceInterface $instance, TokenInterface $token) { $dataStore = $instance->getDataStore(); $loopCardinality = $this->getLoopCardinality(); $loopDataInput = $this->getLoopDataInput(); if ($loopCardinality) { $cardinality = $loopCardinality($dataStore->getData()); return \is_numeric($cardinality) && $cardinality > 0; } else { $dataInput = $this->getInputDataValue($loopDataInput, $dataStore); $isCountable = is_array($dataInput) || $dataInput instanceof Countable; if (!$isCountable) { return false; } $count = \count($dataInput); $isSequentialArray = array_keys($dataInput) === \range(0, $count - 1); if (!$isSequentialArray || $count === 0) { return false; } return true; } } /** * Check if data input is valid * * @param ExecutionInstanceInterface $instance * @param TokenInterface $token * * @return string */ public function getDataInputError(ExecutionInstanceInterface $instance, TokenInterface $token) { $dataStore = $instance->getDataStore(); $loopCardinality = $this->getLoopCardinality(); $loopDataInput = $this->getLoopDataInput(); if ($loopCardinality) { $cardinality = $loopCardinality($dataStore->getData()); if (!\is_numeric($cardinality) && $cardinality >= 0) { return 'Invalid data input, expected a number'; } } else { $loopDataInputName = $loopDataInput->getName(); $dataInput = $this->getInputDataValue($loopDataInput, $dataStore); $isCountable = is_array($dataInput) || $dataInput instanceof Countable; if (!$isCountable) { return "Invalid data input ({$loopDataInputName}), it must be a sequential array"; } $count = \count($dataInput); $isSequentialArray = $count === 0 || array_keys($dataInput) === \range(0, $count - 1); if (!$isSequentialArray) { return "The data input ({$loopDataInputName}) is an object or an associative array, it must be a sequential array"; } } return ''; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/DatePeriod.php
src/ProcessMaker/Nayra/Bpmn/Models/DatePeriod.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use DateInterval; use DateTime; use DateTimeInterface; use Exception; use Iterator; use ProcessMaker\Nayra\Contracts\Bpmn\DatePeriodInterface; /** * DatePeriod represents an ISO8601 Repeating intervals */ class DatePeriod implements DatePeriodInterface { /** * Start date of the period * * @var DateTime */ public $start; public $current; /** * End date of the period * * @var DateTime */ public $end; /** * Interval of the period * * @var DateInterval */ public $interval; /** * Number of recurrences of the period * * @var int */ public $recurrences; public $include_start_date = true; public $include_end_date = false; private $position = 0; private $last; const INF_RECURRENCES = 0; const EXCLUDE_START_DATE = 1; /** * Initialize a DatePeriod. * * Parameters could be: * - ISO8601 Repeating intervals R[n]/start/interval/end * - start, interval, [end|array(end,recurences-1)] */ public function __construct(...$args) { $expression = is_string($args[0]) ? $args[0] : null; //Improve Repeating intervals (R/start/interval/end) configuration if (preg_match('/^R(\d*)\/([^\/]+)\/([^\/]+)\/([^\/]+)$/', $expression, $repeating)) { $this->start = new DateTime($repeating[2]); $this->interval = new DateInterval($repeating[3]); $this->end = new DateTime($repeating[4]); $this->recurrences = $repeating[1] ? $repeating[1] + 1 : self::INF_RECURRENCES; //Improve Repeating intervals (R[n]/start/interval) or (R[n]/interval/end) configuration } elseif (preg_match('/^R(\d*)\/([^\/]+)\/([^\/]+)$/', $expression, $repeating)) { $withoutStart = substr($repeating[2], 0, 1) === 'P'; $this->start = $withoutStart ? null : new DateTime($repeating[2]); $this->interval = new DateInterval($repeating[$withoutStart ? 2 : 3]); $this->end = $withoutStart ? new DateTime($repeating[3]) : null; $this->recurrences = $repeating[1] ? $repeating[1] + 1 : self::INF_RECURRENCES; //Improve Repeating intervals (R[n]/start/interval) configuration } elseif (preg_match('/^R(\d*)\/([^\/]+)$/', $expression, $repeating)) { $this->start = null; $this->interval = new DateInterval($repeating[2]); $this->end = null; $this->recurrences = $repeating[1] ? $repeating[1] + 1 : self::INF_RECURRENCES; } elseif (count($args) === 3 && is_array($args[2])) { $this->start = $args[0]; $this->interval = $args[1]; $this->end = $args[2][0]; $this->recurrences = $args[2][1] + 1; } elseif (count($args) === 2 || count($args) === 3) { $this->start = $args[0]; $this->interval = $args[1]; $this->end = isset($args[2]) && $args[2] instanceof DateTimeInterface ? $args[2] : null; $this->recurrences = isset($args[2]) && is_int($args[2]) ? $args[2] + 1 : self::INF_RECURRENCES; } else { throw new Exception('Invalid DatePeriod definition'); } // Validate properties if (isset($this->start) && !($this->start instanceof DateTimeInterface)) { throw new Exception('Invalid DatePeriod::start definition'); } if (!($this->interval instanceof DateInterval)) { throw new Exception('Invalid DatePeriod::interval definition'); } if (isset($this->end) && !($this->end instanceof DateTimeInterface)) { throw new Exception('Invalid DatePeriod::end definition'); } if (!($this->recurrences >= 0)) { throw new Exception('Invalid DatePeriod::recurrences definition'); } } /** * Get start date time * * @return DateTimeInterface */ public function getStartDate() { return $this->start; } /** * Get date interval * * @return DateInterval */ public function getDateInterval() { return $this->interval; } /** * Get current datetime for an iteration * * @return DateTimeInterface */ public function current() { return $this->current; } /** * Get current position for an iteration * * @return int */ public function key() { return $this->position; } /** * Iterate to the next datetime */ public function next() { $this->position++; $this->current = $this->calc($this->current, 1); } /** * Rewind iteration to the first datetime */ public function rewind() { $this->current = $this->start ?: ($this->end ? $this->calc($this->end, -$this->recurrences) : new DateTime()); $this->last = $this->end ?: $this->calc($this->current, $this->recurrences); $this->position = 0; } /** * Check if iteration continues * * @return bool */ public function valid() { return $this->current <= $this->last; } /** * Calculate next/previos date * * @param DateTimeInterface $date * @param int $count * * @return DateTimeInterface */ private function calc(DateTimeInterface $date, $count) { $date = clone $date; while ($count) { $count <= 0 ?: $date->add($this->interval); $count >= 0 ?: $date->sub($this->interval); $count > 0 ? $count-- : $count++; } return $date; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Participant.php
src/ProcessMaker/Nayra/Bpmn/Models/Participant.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\ParticipantTrait; use ProcessMaker\Nayra\Contracts\Bpmn\ParticipantInterface; /** * Activity implementation. */ class Participant implements ParticipantInterface { use ParticipantTrait; }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Activity.php
src/ProcessMaker/Nayra/Bpmn/Models/Activity.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\ActivityTrait; use ProcessMaker\Nayra\Bpmn\Events\ActivityActivatedEvent; use ProcessMaker\Nayra\Bpmn\Events\ActivityClosedEvent; use ProcessMaker\Nayra\Bpmn\Events\ActivityCompletedEvent; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; /** * Activity implementation. */ class Activity implements ActivityInterface { use ActivityTrait; /** * Array map of custom event classes for the bpmn element. * * @return array */ protected function getBpmnEventClasses() { return [ ActivityInterface::EVENT_ACTIVITY_ACTIVATED => ActivityActivatedEvent::class, ActivityInterface::EVENT_ACTIVITY_COMPLETED => ActivityCompletedEvent::class, ActivityInterface::EVENT_ACTIVITY_CLOSED => ActivityClosedEvent::class, ]; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/DataOutput.php
src/ProcessMaker/Nayra/Bpmn/Models/DataOutput.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\FlowElementTrait; use ProcessMaker\Nayra\Contracts\Bpmn\DataOutputInterface; /** * Data output implementation. */ class DataOutput implements DataOutputInterface { use FlowElementTrait; /** * Get the item subject. * * @return mixed */ public function getItemSubject() { return $this->getProperty(static::BPMN_PROPERTY_ITEM_SUBJECT); } /** * Get true is the data input is a collection. * * @return bool */ public function isCollection() { return $this->getProperty(static::BPMN_PROPERTY_IS_COLLECTION); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/OutputSet.php
src/ProcessMaker/Nayra/Bpmn/Models/OutputSet.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\OutputSetInterface; /** * An OutputSet is a collection of DataOutputs elements that together can be * produced as output. */ class OutputSet implements OutputSetInterface { use BaseTrait; /** * Initialize input set. */ protected function initInputSet() { $this->setDataOutputs(new Collection); } /** * Get DataOutput elements that MAY collectively be outputted. * * @return DataOutputInterface[] */ public function getDataOutputs() { return $this->getProperty(static::BPMN_PROPERTY_DATA_OUTPUTS); } /** * Set DataOutput elements that MAY collectively be outputted. * * @param CollectionInterface $dataOutputs * * @return $this */ public function setDataOutputs(CollectionInterface $dataOutputs) { return $this->setProperty(static::BPMN_PROPERTY_DATA_OUTPUTS, $dataOutputs); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/StartEvent.php
src/ProcessMaker/Nayra/Bpmn/Models/StartEvent.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\StartEventTrait; use ProcessMaker\Nayra\Contracts\Bpmn\MessageListenerInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StartEventInterface; /** * Class StartEvent */ class StartEvent implements StartEventInterface, MessageListenerInterface { use StartEventTrait; /** * Array map of custom event classes for the bpmn element. * * @return array */ protected function getBpmnEventClasses() { return []; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/BoundaryEvent.php
src/ProcessMaker/Nayra/Bpmn/Models/BoundaryEvent.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\BoundaryEventTrait; use ProcessMaker\Nayra\Contracts\Bpmn\BoundaryEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageListenerInterface; /** * BoundaryEvent implementation. */ class BoundaryEvent implements BoundaryEventInterface, MessageListenerInterface { use BoundaryEventTrait; /** * Get BPMN event classes. * * @return array */ protected function getBpmnEventClasses() { return []; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/ServiceTask.php
src/ProcessMaker/Nayra/Bpmn/Models/ServiceTask.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use Exception; use ProcessMaker\Nayra\Bpmn\ActivityTrait; use ProcessMaker\Nayra\Bpmn\Events\ActivityActivatedEvent; use ProcessMaker\Nayra\Bpmn\Events\ActivityClosedEvent; use ProcessMaker\Nayra\Bpmn\Events\ActivityCompletedEvent; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ServiceTaskInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; /** * This activity will raise an exception when executed. */ class ServiceTask implements ServiceTaskInterface { use ActivityTrait; /** * Initialize the service task */ protected function initServiceTask() { $this->attachEvent( ActivityInterface::EVENT_ACTIVITY_ACTIVATED, function ($self, TokenInterface $token) { $this->notifyEvent(ServiceTaskInterface::EVENT_SERVICE_TASK_ACTIVATED, $this, $token); } ); } /** * Array map of custom event classes for the bpmn element. * * @return array */ protected function getBpmnEventClasses() { return [ ActivityInterface::EVENT_ACTIVITY_ACTIVATED => ActivityActivatedEvent::class, ActivityInterface::EVENT_ACTIVITY_COMPLETED => ActivityCompletedEvent::class, ActivityInterface::EVENT_ACTIVITY_CLOSED => ActivityClosedEvent::class, ]; } /** * Sets the service task implementation * * @param mixed $implementation * * @return $this */ public function setImplementation($implementation) { $this->setProperty(ServiceTaskInterface::BPMN_PROPERTY_IMPLEMENTATION, $implementation); return $this; } /** * Returns the service task implementation * * @return mixed */ public function getImplementation() { return $this->getProperty(ServiceTaskInterface::BPMN_PROPERTY_IMPLEMENTATION); } /** * Runs the Service Task * * @param TokenInterface $token * * @return $this */ public function run(TokenInterface $token) { //if the script runs correctly complete te activity, otherwise set the token to failed state if ($this->executeService($token, $this->getImplementation())) { $this->complete($token); } else { $token->setStatus(ActivityInterface::TOKEN_STATE_FAILING); } return $this; } /** * Service Task runner for testing purposes * * @param TokenInterface $token * @param mixed $implementation * * @return bool */ private function executeService(TokenInterface $token, $implementation) { $result = true; try { $callable = is_string($implementation) && strpos($implementation, '@') ? explode('@', $implementation) : $implementation; call_user_func($callable); } catch (Exception $exception) { $result = false; } return $result; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/InclusiveGateway.php
src/ProcessMaker/Nayra/Bpmn/Models/InclusiveGateway.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\InclusiveGatewayTrait; use ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\InclusiveGatewayInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; /** * Inclusive Gateway * * Synchronizes a certain subset of branches out of the set * of concurrent incoming branches (merging behavior). Further on, each firing * leads to the creation of threads on a certain subset out of the set of * outgoing branches (branching behavior). */ class InclusiveGateway implements InclusiveGatewayInterface { use InclusiveGatewayTrait; /** * For gateway connections. * * @param FlowNodeInterface $target * @param callable $condition * @param bool $isDefault * @param RepositoryInterface $factory * * @return $this */ public function createConditionedFlowTo( FlowNodeInterface $target, callable $condition, $isDefault, RepositoryInterface $factory ) { $this->createFlowTo($target, $factory, [ FlowInterface::BPMN_PROPERTY_CONDITION_EXPRESSION => $condition, FlowInterface::BPMN_PROPERTY_IS_DEFAULT => $isDefault, ]); return $this; } /** * Array map of custom event classes for the BPMN element. * * @return array */ protected function getBpmnEventClasses() { return []; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/DataStoreCollection.php
src/ProcessMaker/Nayra/Bpmn/Models/DataStoreCollection.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\DataStoreCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\DataStoreInterface; /** * DataStore collection. */ class DataStoreCollection extends Collection implements DataStoreCollectionInterface { /** * Add element to the collection. * * @param DataStoreInterface $element * * @return $this */ public function add(DataStoreInterface $element) { $this->push($element); return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/ParallelGateway.php
src/ProcessMaker/Nayra/Bpmn/Models/ParallelGateway.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\ParallelGatewayTrait; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ParallelGatewayInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; use ProcessMaker\Nayra\Exceptions\InvalidSequenceFlowException; /** * Parallel gateway implementation. */ class ParallelGateway implements ParallelGatewayInterface { use ParallelGatewayTrait; /** * For gateway connections. * * @param FlowNodeInterface $target * @param callable $condition * @param bool $isDefault * @param RepositoryInterface $factory * * @return $this */ public function createConditionedFlowTo( FlowNodeInterface $target, callable $condition, $isDefault, RepositoryInterface $factory ) { throw new InvalidSequenceFlowException('A parallel gateway can not have conditioned outgoing flows.'); } /** * Array map of custom event classes for the bpmn element. * * @return array */ protected function getBpmnEventClasses() { return []; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/Message.php
src/ProcessMaker/Nayra/Bpmn/Models/Message.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Contracts\Bpmn\ItemDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageFlowInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageInterface; /** * Message implementation. */ class Message implements MessageInterface { use BaseTrait; /** * @var string */ private $id; /** * @var string */ private $name; /** * @var ItemDefinitionInterface */ private $item; /** * @var MessageFlowInterface */ private $messageFlow; /** * Get the ItemDefinition is used to define the payload of the Message. * * @return ItemDefinitionInterface */ public function getItem() { return $this->item; } /** * Allows to set the item * * @param ItemDefinitionInterface $item * * @return $this */ public function setItem(ItemDefinitionInterface $item) { $this->item = $item; return $this; } /** * Returns the id of the message * * @return string */ public function getId() { return $this->id; } /** * Sets the id of the message * @param string $value */ public function setId($value) { $this->id = $value; } /** * Returns the name of the message * * @return string */ public function getName() { return $this->name; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/ScriptTask.php
src/ProcessMaker/Nayra/Bpmn/Models/ScriptTask.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use Exception; use ProcessMaker\Nayra\Bpmn\ActivityTrait; use ProcessMaker\Nayra\Bpmn\Events\ActivityActivatedEvent; use ProcessMaker\Nayra\Bpmn\Events\ActivityClosedEvent; use ProcessMaker\Nayra\Bpmn\Events\ActivityCompletedEvent; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MultiInstanceLoopCharacteristicsInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ScriptTaskInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; /** * This activity will raise an exception when executed. */ class ScriptTask implements ScriptTaskInterface { use ActivityTrait; /** * Configure the activity to evaluate script tasks */ protected function initActivity() { $this->attachEvent( ActivityInterface::EVENT_ACTIVITY_ACTIVATED, function ($self, TokenInterface $token) { $this->notifyEvent(ScriptTaskInterface::EVENT_SCRIPT_TASK_ACTIVATED, $this, $token); } ); } /** * Array map of custom event classes for the bpmn element. * * @return array */ protected function getBpmnEventClasses() { return [ ActivityInterface::EVENT_ACTIVITY_ACTIVATED => ActivityActivatedEvent::class, ActivityInterface::EVENT_ACTIVITY_COMPLETED => ActivityCompletedEvent::class, ActivityInterface::EVENT_ACTIVITY_CLOSED => ActivityClosedEvent::class, ]; } /** * Sets the script format of the script task * * @param string $scriptFormat */ public function setScriptFormat($scriptFormat) { $this->setProperty(ScriptTaskInterface::BPMN_PROPERTY_SCRIPT_FORMAT, $scriptFormat); } /** * Sets the script of the script task * * @param string $script */ public function setScript($script) { $this->setProperty(ScriptTaskInterface::BPMN_PROPERTY_SCRIPT, $script); } /** * Returns the script format of the script task * * @return string */ public function getScriptFormat() { return $this->getProperty(ScriptTaskInterface::BPMN_PROPERTY_SCRIPT_FORMAT); } /** * Returns de Script of the script task * * @return $string */ public function getScript() { return $this->getProperty(ScriptTaskInterface::BPMN_PROPERTY_SCRIPT); } /** * Runs the ScriptTask * @param TokenInterface $token */ public function runScript(TokenInterface $token) { //if the script runs correctly complete te activity, otherwise set the token to failed state if ($this->executeScript($token, $this->getScript())) { $this->complete($token); } else { $token->setStatus(ActivityInterface::TOKEN_STATE_FAILING); } } /** * Script runner fot testing purposes that just evaluates the sent php code * * @param TokenInterface $token * @param string $script * @return bool */ private function executeScript(TokenInterface $token, $script) { $result = true; try { $element = $token->getOwnerElement(); $loop = $element->getLoopCharacteristics(); $isMulti = $loop instanceof MultiInstanceLoopCharacteristicsInterface && $loop->isExecutable(); if ($isMulti) { $data = $token->getProperty('data', []); } else { $data = $token->getInstance()->getDataStore()->getData(); } $newData = eval($script); if (gettype($newData) === 'array') { $data = array_merge($data, $newData); if ($isMulti) { $token->setProperty('data', $data); } else { $token->getInstance()->getDataStore()->setData($data); } } } catch (Exception $e) { $result = false; } return $result; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/ExclusiveGateway.php
src/ProcessMaker/Nayra/Bpmn/Models/ExclusiveGateway.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\ExclusiveGatewayTrait; use ProcessMaker\Nayra\Contracts\Bpmn\ExclusiveGatewayInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; /** * Exclusive Gateway * * Has pass-through semantics for a set of incoming branches * (merging behavior). Further on, each activation leads to the activation of * exactly one out of the set of outgoing branches (branching behavior) */ class ExclusiveGateway implements ExclusiveGatewayInterface { use ExclusiveGatewayTrait; /** * For gateway connections. * * @param FlowNodeInterface $target * @param callable $condition * @param bool $isDefault * @param RepositoryInterface $factory * * @return $this */ public function createConditionedFlowTo( FlowNodeInterface $target, callable $condition, $isDefault, RepositoryInterface $factory ) { $this->createFlowTo($target, $factory, [ FlowInterface::BPMN_PROPERTY_CONDITION_EXPRESSION => $condition, FlowInterface::BPMN_PROPERTY_IS_DEFAULT => $isDefault, ]); return $this; } /** * Array map of custom event classes for the bpmn element. * * @return array */ protected function getBpmnEventClasses() { return []; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/MessageEventDefinition.php
src/ProcessMaker/Nayra/Bpmn/Models/MessageEventDefinition.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\EventDefinitionTrait; use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\DataStoreInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\FlowNodeInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageEventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\MessageInterface; use ProcessMaker\Nayra\Contracts\Bpmn\OperationInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ThrowEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * MessageEventDefinition class */ class MessageEventDefinition implements MessageEventDefinitionInterface { use EventDefinitionTrait; /** * Get the message. * * @return MessageInterface */ public function getPayload() { return $this->getProperty(static::BPMN_PROPERTY_MESSAGE); } /** * Sets the message to be used in the message event definition * * @param MessageInterface $message * * @return $this */ public function setPayload(MessageInterface $message) { return $this->setProperty(static::BPMN_PROPERTY_MESSAGE, $message); } /** * Get the Operation that is used by the Message Event. * * @return OperationInterface */ public function getOperation() { return $this->getProperty(static::BPMN_PROPERTY_OPERATION); } /** * Sets the operation of the message event definition * * @param OperationInterface $operation * @return $this */ public function setOperation(OperationInterface $operation) { return $this->setProperty(static::BPMN_PROPERTY_OPERATION, $operation); } /** * Assert the event definition rule for trigger the event. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return bool */ public function assertsRule(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { return true; } /** * Implement the event definition behavior when an event is triggered. * * @param EventDefinitionInterface $event * @param FlowNodeInterface $target * @param ExecutionInstanceInterface|null $instance * @param TokenInterface|null $token * * @return $this */ public function execute(EventDefinitionInterface $event, FlowNodeInterface $target, ExecutionInstanceInterface $instance = null, TokenInterface $token = null) { if ($token !== null) { $throwEvent = $token->getOwnerElement(); if ($throwEvent instanceof ThrowEventInterface && $target instanceof CatchEventInterface) { $this->executeMessageMapping($throwEvent, $target, $instance, $token); } } return $this; } /** * Map a message payload from a ThrowEvent through an optional CatchEvent mapping * into the instance data store. * * @param ThrowEventInterface $throwEvent * @param CatchEventInterface $catchEvent * @param ExecutionInstanceInterface $instance * @param TokenInterface $token * * @return void */ private function executeMessageMapping(ThrowEventInterface $throwEvent, CatchEventInterface $catchEvent, ExecutionInstanceInterface $instance, TokenInterface $token): void { $sourceMaps = $throwEvent->getDataInputAssociations(); $targetMaps = $catchEvent->getDataOutputAssociations(); $targetStore = $instance->getDataStore(); // Source of data is the token's instance store if present; otherwise a fresh store. $sourceStore = $token->getInstance()?->getDataStore() ?? new DataStore(); // If target mappings exist we stage into a buffer; otherwise write straight to the instance store. $bufferStore = !count($targetMaps) ? $targetStore : new DataStore(); // 1) Source mappings: source → buffer/instance $this->evaluateMessagePayload($sourceMaps, $sourceStore, $bufferStore); // 2) Optional target mappings: buffer → instance if (count($targetMaps)) { $this->evaluateMessagePayload($targetMaps, $bufferStore, $targetStore); } } /** * Evaluate the message payload * * @param CollectionInterface $associations * @param DataStoreInterface $sourceStore * @param DataStoreInterface $targetStore * * @return void */ private function evaluateMessagePayload(CollectionInterface $associations, DataStoreInterface $sourceStore, DataStoreInterface $targetStore): void { $assignments = []; foreach ($associations as $association) { $source = $association->getSource(); $target = $association->getTarget(); $hasSource = $source && $source->getName(); $hasTarget = $target && $target->getName(); // Base data always starts from full source store $data = $sourceStore->getData(); // Optionally add a direct reference to the source value if ($hasSource) { $data['sourceRef'] = $sourceStore->getDotData($source->getName()); } // Transformation and assignments build up the assignments list $this->applyTransformation($association, $data, $assignments, $hasTarget, $hasSource); $this->evaluateAssignments($association, $data, $assignments); } // Flush all assignments into target store foreach ($assignments as $assignment) { $targetStore->setDotData($assignment['key'], $assignment['value']); } } /** * Apply transformation to the data and add to payload * * @param mixed $association * @param array $data * @param array &$payload * @param bool $hasTarget * @param bool $hasSource */ private function applyTransformation($association, array $data, array &$payload, bool $hasTarget, bool $hasSource) { $transformation = $association->getTransformation(); $target = $association->getTarget(); if ($hasTarget && $transformation && is_callable($transformation)) { $value = $transformation($data); $payload[] = ['key' => $target->getName(), 'value' => $value]; } elseif ($hasTarget && $hasSource) { $payload[] = ['key' => $target->getName(), 'value' => $data['sourceRef']]; } } /** * Evaluate assignments and add to payload * * @param mixed $association * @param array $data * @param array &$payload */ private function evaluateAssignments($association, array $data, array &$payload) { $assignments = $association->getAssignments(); foreach ($assignments as $assignment) { $from = $assignment->getFrom(); $to = trim($assignment->getTo()?->getBody()); if (is_callable($from) && !empty($to)) { $payload[] = ['key' => $to, 'value' => $from($data)]; } } } /** * Check if the $eventDefinition should be catch * * @param EventDefinitionInterface $eventDefinition * * @return bool */ public function shouldCatchEventDefinition(EventDefinitionInterface $eventDefinition) { $targetPayload = $this->getPayload(); $sourcePayload = $eventDefinition->getPayload(); return (!$targetPayload && !$sourcePayload) || ($targetPayload && $sourcePayload && $targetPayload->getId() === $sourcePayload->getId()); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Models/ArtifactCollection.php
src/ProcessMaker/Nayra/Bpmn/Models/ArtifactCollection.php
<?php namespace ProcessMaker\Nayra\Bpmn\Models; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\ArtifactCollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ArtifactInterface; /** * Collection of artifacts. */ class ArtifactCollection extends Collection implements ArtifactCollectionInterface { /** * Add an element to the collection. * * @param ArtifactInterface $element * * @return $this */ public function add(ArtifactInterface $element) { $this->push($element); return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Events/ActivityCompletedEvent.php
src/ProcessMaker/Nayra/Bpmn/Events/ActivityCompletedEvent.php
<?php namespace ProcessMaker\Nayra\Bpmn\Events; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; /** * Event raised when and activity is activated. */ class ActivityCompletedEvent { /** * @var ActivityInterface */ public $activity; /** * @var \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface */ public $token; /** * ActivityCompletedEvent constructor. * * @param ActivityInterface $activity * @param TokenInterface $token */ public function __construct(ActivityInterface $activity, TokenInterface $token) { $this->activity = $activity; $this->token = $token; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Events/ActivityActivatedEvent.php
src/ProcessMaker/Nayra/Bpmn/Events/ActivityActivatedEvent.php
<?php namespace ProcessMaker\Nayra\Bpmn\Events; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; /** * Event raised when and activity is activated. */ class ActivityActivatedEvent { /** * @var ActivityInterface */ public $activity; /** * @var \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface */ public $token; /** * ActivityActivatedEvent constructor. * * @param ActivityInterface $activity * @param TokenInterface $token */ public function __construct(ActivityInterface $activity, TokenInterface $token) { $this->activity = $activity; $this->token = $token; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Events/ProcessInstanceCreatedEvent.php
src/ProcessMaker/Nayra/Bpmn/Events/ProcessInstanceCreatedEvent.php
<?php namespace ProcessMaker\Nayra\Bpmn\Events; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Event raised when process instance is created. */ class ProcessInstanceCreatedEvent { /** * @var \ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface */ public $process; /** * @var \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface */ public $instance; /** * ProcessInstanceCreatedEvent constructor. * * @param ProcessInterface $process * @param ExecutionInstanceInterface $instance */ public function __construct(ProcessInterface $process, ExecutionInstanceInterface $instance) { $this->process = $process; $this->instance = $instance; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Events/ActivityClosedEvent.php
src/ProcessMaker/Nayra/Bpmn/Events/ActivityClosedEvent.php
<?php namespace ProcessMaker\Nayra\Bpmn\Events; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; /** * Event raised when and activity is closed. */ class ActivityClosedEvent { /** * @var ActivityInterface */ public $activity; /** * @var \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface */ public $token; /** * ActivityClosedEvent constructor. * * @param ActivityInterface $activity * @param TokenInterface $token */ public function __construct(ActivityInterface $activity, TokenInterface $token) { $this->activity = $activity; $this->token = $token; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Bpmn/Events/ProcessInstanceCompletedEvent.php
src/ProcessMaker/Nayra/Bpmn/Events/ProcessInstanceCompletedEvent.php
<?php namespace ProcessMaker\Nayra\Bpmn\Events; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Event raised when process instance is completed. */ class ProcessInstanceCompletedEvent { /** * @var \ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface */ public $process; /** * @var \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface */ public $instance; /** * ProcessInstanceCreatedEvent constructor. * * @param ProcessInterface $process * @param ExecutionInstanceInterface $instance */ public function __construct(ProcessInterface $process, ExecutionInstanceInterface $instance) { $this->process = $process; $this->instance = $instance; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Engine/DemoModeTrait.php
src/ProcessMaker/Nayra/Engine/DemoModeTrait.php
<?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; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Engine/EngineTrait.php
src/ProcessMaker/Nayra/Engine/EngineTrait.php
<?php namespace ProcessMaker\Nayra\Engine; use ProcessMaker\Nayra\Bpmn\Models\EventDefinitionBus; use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CollaborationInterface; use ProcessMaker\Nayra\Contracts\Bpmn\DataStoreInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; use ProcessMaker\Nayra\Contracts\Engine\EngineInterface; use ProcessMaker\Nayra\Contracts\Engine\EventDefinitionBusInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; use ProcessMaker\Nayra\Contracts\Engine\JobManagerInterface; use ProcessMaker\Nayra\Contracts\Repositories\StorageInterface; use ProcessMaker\Nayra\Contracts\Storage\BpmnDocumentInterface; use ProcessMaker\Nayra\Storage\BpmnDocument; /** * Engine base behavior. */ trait EngineTrait { use DemoModeTrait; /** * Instances of process. * * @var ExecutionInstance[] */ private $executionInstances = []; /** * Loaded processes. * * @var ProcessInterface[] */ private $processes = []; /** * Engine data store. * * @var DataStoreInterface */ private $dataStore; protected $jobManager; /** * Actions to be executed after runToNextState is solved * * @var array */ private $onNextState = []; /** * Event definition bus * * @var EventDefinitionBusInterface */ protected $eventDefinitionBus; /** * Execute all the process transitions. * * @return bool */ public function step() { $sum = 0; //Execute transitions per instance foreach ($this->executionInstances as $executionInstance) { $sum += $executionInstance->getTransitions()->sum(function (TransitionInterface $transition) use ($executionInstance) { $result = $transition->execute($executionInstance) ? 1 : 0; return $result; }) > 0; } //If there are no pending transitions, next state callbacks are executed if (!$sum && $sum = count($this->onNextState)) { while ($action = array_shift($this->onNextState)) { $action(); } } return $sum; } /** * Run to the next state. * * @param int $maxIterations * * @return bool */ public function runToNextState($maxIterations = 0) { $step = true; while ($step) { $step = $this->step(); if (!$step) { $this->dispatchConditionalEvents(); $step = $this->step(); } $maxIterations--; if ($maxIterations === 0) { return false; } } return true; } /** * Defer the callback to be executed after the next state cycle. * * @param callable $callable * * @return EngineInterface */ public function nextState(callable $callable) { $this->onNextState[] = $callable; return $this; } /** * Create an execution instance of a process. * * @param ProcessInterface $process * @param DataStoreInterface $data * @param \ProcessMaker\Nayra\Contracts\Bpmn\EventInterface|null $event * * @return ExecutionInstanceInterface */ public function createExecutionInstance(ProcessInterface $process, DataStoreInterface $data, EventInterface $event = null) { $this->loadProcess($process); $instanceRepo = $this->repository->createExecutionInstanceRepository(); $executionInstance = $instanceRepo->createExecutionInstance($process, $data); $process->addInstance($executionInstance); $executionInstance->setProcess($process); $executionInstance->setDataStore($data); $executionInstance->linkToEngine($this); $this->executionInstances[] = $executionInstance; $instanceRepo->persistInstanceCreated($executionInstance); $process->notifyInstanceEvent(ProcessInterface::EVENT_PROCESS_INSTANCE_CREATED, $executionInstance, $event); return $executionInstance; } /** * Load an execution instance from the storage. * * @param string $id * @param StorageInterface $storage * * @return ExecutionInstanceInterface|null */ public function loadExecutionInstance($id, StorageInterface $storage) { // If exists return the already loaded instance by id foreach ($this->executionInstances as $executionInstance) { if ($executionInstance->getId() === $id) { return $executionInstance; } } // Create and load an instance by id $repository = $this->getRepository()->createExecutionInstanceRepository(); $executionInstance = $repository->loadExecutionInstanceByUid($id, $storage); if (!$executionInstance) { return; } $this->loadProcess($executionInstance->getProcess()); $executionInstance->linkToEngine($this); $executionInstance->getProcess()->addInstance($executionInstance); $this->executionInstances[] = $executionInstance; return $executionInstance; } /** * Close all the execution instances. * * @return bool */ public function closeExecutionInstances() { $this->executionInstances = array_filter( $this->executionInstances, function (ExecutionInstanceInterface $executionInstance) { return !$executionInstance->close(); } ); return count($this->executionInstances) === 0; } /** * Get the engine data store used for global evaluations. * * @return DataStoreInterface */ public function getDataStore() { return $this->dataStore; } /** * Set the engine data store used for global evaluations. * * @param DataStoreInterface $dataStore * * @return $this */ public function setDataStore(DataStoreInterface $dataStore) { $this->dataStore = $dataStore; return $this; } /** * Load a process into the engine * * @param ProcessInterface $process * * @return $this */ public function loadProcess(ProcessInterface $process) { $process->setEngine($this); if (!in_array($process, $this->processes, true)) { $this->processes[] = $process; $this->registerCatchEvents($process); } return $this; } /** * Load definitions into BPMN Engine * * @param BpmnDocumentInterface $document * * @return EngineInterface */ public function loadBpmnDocument(BpmnDocumentInterface $document) { $nodes = $document->getElementsByTagNameNS(BpmnDocument::BPMN_MODEL, 'collaboration'); foreach ($nodes as $node) { $this->loadCollaboration($node->getBpmnElementInstance()); } $processes = $document->getElementsByTagNameNS(BpmnDocument::BPMN_MODEL, 'process'); foreach ($processes as $process) { $this->loadProcess($process->getBpmnElementInstance()); } return $this; } /** * Load a collaboration * * @param CollaborationInterface $collaboration * * @return EngineInterface */ public function loadCollaboration(CollaborationInterface $collaboration) { $this->getEventDefinitionBus()->setCollaboration($collaboration); return $this; } /** * Register the catch events of the process. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface $process */ private function registerCatchEvents(ProcessInterface $process) { foreach ($process->getEvents() as $event) { if ($event instanceof CatchEventInterface) { $event->registerWithEngine($this); } } } /** * Get the engine job manager for timer tasks and events. * * @return JobManagerInterface */ public function getJobManager() { return $this->jobManager; } /** * Set the engine job manager for timer tasks and events. * * @param JobManagerInterface|null $jobManager * * @return $this */ public function setJobManager(JobManagerInterface $jobManager = null) { $this->jobManager = $jobManager; return $this; } /** * Set a event definitions bus for the engine * * @param \ProcessMaker\Nayra\Contracts\Engine\EventDefinitionBusInterface $eventDefinitionBus * * @return EngineInterface */ public function setEventDefinitionBus(EventDefinitionBusInterface $eventDefinitionBus) { $this->eventDefinitionBus = $eventDefinitionBus; return $this; } /** * Get the event definitions bus of the engine * * @return EventDefinitionBusInterface */ public function getEventDefinitionBus() { $this->eventDefinitionBus = $this->eventDefinitionBus ?: new EventDefinitionBus; return $this->eventDefinitionBus; } /** * Dispatch conditional events * * @return void */ private function dispatchConditionalEvents() { $this->getEventDefinitionBus() ->dispatchEventDefinition( $this, $this->getRepository()->createConditionalEventDefinition(), null ); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Engine/ExecutionInstance.php
src/ProcessMaker/Nayra/Engine/ExecutionInstance.php
<?php namespace ProcessMaker\Nayra\Engine; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; /** * Execution instance for the engine. */ class ExecutionInstance implements ExecutionInstanceInterface { use ExecutionInstanceTrait; }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Engine/JobManagerTrait.php
src/ProcessMaker/Nayra/Engine/JobManagerTrait.php
<?php namespace ProcessMaker\Nayra\Engine; use DateTimeInterface; use ProcessMaker\Nayra\Bpmn\Models\DatePeriod; /** * JobManagerTrait */ trait JobManagerTrait { /** * Get the next datetime event of a cycle. * * @param DatePeriod $cycle * @param DateTimeInterface $last * * @return DateTimeInterface */ protected function getNextDateTimeCycle(DatePeriod $cycle, DateTimeInterface $last) { $nextDateTime = null; foreach ($cycle as $i => $dateTime) { if ($last < $dateTime) { $nextDateTime = $dateTime; break; } } return $nextDateTime; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/src/ProcessMaker/Nayra/Engine/ExecutionInstanceTrait.php
src/ProcessMaker/Nayra/Engine/ExecutionInstanceTrait.php
<?php namespace ProcessMaker\Nayra\Engine; use ProcessMaker\Nayra\Bpmn\BaseTrait; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\DataStoreInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\EngineInterface; /** * Execution instance for the engine. */ trait ExecutionInstanceTrait { use BaseTrait; /** * Process executed. * * @var ProcessInterface */ private $process; /** * Data used for the process. * * @var DataStoreInterface */ private $dataStore; /** * Transitions to be executed. * * @var \ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface[] */ private $transitions; /** * @var \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface[]|\ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface */ private $tokens; public $uniqid; /** * ExecutionInstance constructor. * * @param EngineInterface $engine * @param ProcessInterface $process * @param DataStoreInterface $data */ protected function initExecutionInstance() { $this->uniqid = \uniqid('', true); $this->tokens = new Collection; } /** * Link the instance to a engine, process and data store. * * @param EngineInterface $engine * @param ProcessInterface $process * @param DataStoreInterface $data */ public function linkTo(EngineInterface $engine, ProcessInterface $process, DataStoreInterface $data) { $process->setDispatcher($engine->getDispatcher()); $process->addInstance($this); $this->process = $process; $this->dataStore = $data; $this->transitions = $process->getTransitions($engine->getRepository()); } /** * Get the process executed. * * @return ProcessInterface */ public function getProcess() { return $this->process; } /** * Set the process executed. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface $process * * @return $this */ public function setProcess(ProcessInterface $process) { $this->process = $process; return $this; } /** * Get the data context. * * @return DataStoreInterface */ public function getDataStore() { return $this->dataStore; } /** * Set the data context. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\DataStoreInterface $dataStore * * @return $this */ public function setDataStore(DataStoreInterface $dataStore) { $this->dataStore = $dataStore; return $this; } /** * Get transitions. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface[]|\ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface */ public function getTransitions() { return $this->transitions; } /** * Link the instance to an engine. * * @param \ProcessMaker\Nayra\Contracts\Engine\EngineInterface $engine * * @return $this */ public function linkToEngine(EngineInterface $engine) { $this->getProcess()->setDispatcher($engine->getDispatcher()); $this->transitions = $this->getProcess()->getTransitions($engine->getRepository()); return $this; } /** * Close the execution instance. * * @return bool */ public function close() { $tokens = $this->getTokens()->toArray(); foreach ($tokens as $token) { $token->setStatus(ActivityInterface::TOKEN_STATE_CLOSED); } return true; } /** * Add a token to the current instance. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface $token * * @return $this */ public function addToken(TokenInterface $token) { $this->tokens->push($token); return $this; } /** * Remove a token from the current instance. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface $token * * @return $this */ public function removeToken(TokenInterface $token) { $tokenIndex = $this->tokens->indexOf($token); $this->tokens->splice($tokenIndex, 1); return $this; } /** * Get all tokens from the current instance. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface */ public function getTokens() { return $this->tokens; } /** * Get the engine. * * @return EngineInterface */ public function getEngine() { return $this->getProcess()->getEngine(); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Contracts/TestOneInterface.php
tests/ProcessMaker/Test/Contracts/TestOneInterface.php
<?php namespace ProcessMaker\Test\Contracts; /** * Interface to be used in the test * * @see \ProcessMaker\Nayra\RepositoryTest */ interface TestOneInterface { /** * Test method */ public function dummyFunction(); }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Contracts/TestTwoInterface.php
tests/ProcessMaker/Test/Contracts/TestTwoInterface.php
<?php namespace ProcessMaker\Test\Contracts; /** * Interface to be used in the test * * @see \ProcessMaker\Nayra\RepositoryTest */ interface TestTwoInterface { /** * Test method */ public function dummyFunction(); }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Models/TestBetsy.php
tests/ProcessMaker/Test/Models/TestBetsy.php
<?php namespace ProcessMaker\Test\Models; use Exception; /** * Test class for evaluate expression used in betsy BPMN files. */ class TestBetsy { public $data; private $code; /** * Class to test betsy processes. * * @param mixed $data * @param string $expression */ public function __construct($data, $expression) { $this->data = $data; $isDotNamedExpression = preg_match('/^[a-zA-Z_][a-zA-Z0-9_\.]+$/', trim($expression)) && $expression !== 'true' && $expression !== 'false'; if ($isDotNamedExpression) { $this->code = '$this->getDotNotationValue($this->data, ' . var_export(trim($expression), true) . ')'; return; } $tokens = token_get_all('<?php ' . $expression); $tokens[0] = ''; $code = ''; foreach ($tokens as $token) { if (is_array($token) && $token[1] === 'test') { $code .= '$' . $token[1]; } elseif ($token === '.') { $code .= '->'; } else { $code .= is_array($token) ? $token[1] : $token; } } $this->code = $code; } /** * Check if the data contains and item by name. * * @param string $name * * @return bool */ public function contains($name) { return isset($this->data[$name]); } /** * Evaluate the code. * * @return mixed */ public function call() { $test = $this; $data = $this->data; return eval('return ' . $this->code . ';'); } private function throwException($message) { throw new Exception($message); } private function getDotNotationValue($array, $dotNotation) { $keys = explode('.', $dotNotation); foreach ($keys as $key) { if (!isset($array[$key])) { return null; } $array = $array[$key]; } return $array; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Models/TestTwoClassWithArgumentsConstructor.php
tests/ProcessMaker/Test/Models/TestTwoClassWithArgumentsConstructor.php
<?php namespace ProcessMaker\Test\Models; use ProcessMaker\Test\Contracts\TestTwoInterface; /** * TestOneClassWithEmptyConstructor */ class TestTwoClassWithArgumentsConstructor implements TestTwoInterface { public $aField; public $anotherField; /** * Test constructor * * @param mixed $field1 * @param mixed $field2 */ public function __construct($field1, $field2) { $this->aField = $field1; $this->anotherField = $field2; } /** * Test function * * @return string */ public function dummyFunction() { return 'test'; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Models/CustomProcess.php
tests/ProcessMaker/Test/Models/CustomProcess.php
<?php namespace ProcessMaker\Test\Models; use ProcessMaker\Models\ActivityCollection; use ProcessMaker\Models\ArtifactCollection; use ProcessMaker\Models\DataStoreCollection; use ProcessMaker\Models\EventCollection; use ProcessMaker\Models\FlowCollection; use ProcessMaker\Models\GatewayCollection; use ProcessMaker\Models\ProcessCompletedEvent; use ProcessMaker\Nayra\Bpmn\ProcessTrait; use ProcessMaker\Nayra\Contracts\Bpmn\ProcessInterface; /** * Process implementation */ class CustomProcess implements ProcessInterface { use ProcessTrait; /** * Process constructor. * * @param array ...$args */ public function __construct(...$args) { $this->bootElement($args); $this->setActivities(new ActivityCollection); $this->setGateways(new GatewayCollection); $this->setEvents(new EventCollection); $this->setFlows(new FlowCollection); $this->setArtifacts(new ArtifactCollection); $this->setDataStores(new DataStoreCollection); } /** * Defined BPMN event classes. * * @return array */ protected function getBpmnEventClasses() { return [ ProcessInterface::EVENT_PROCESS_INSTANCE_COMPLETED => ProcessCompletedEvent::class, ]; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Models/TokenRepository.php
tests/ProcessMaker/Test/Models/TokenRepository.php
<?php namespace ProcessMaker\Test\Models; use Exception; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Bpmn\Models\Token; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\EventBasedGatewayInterface; use ProcessMaker\Nayra\Contracts\Bpmn\GatewayInterface; use ProcessMaker\Nayra\Contracts\Bpmn\StartEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\ThrowEventInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Repositories\TokenRepositoryInterface; /** * Token Repository. */ class TokenRepository implements TokenRepositoryInterface { public $persistCalls = 0; public static $failNextPersistanceCall = false; /** * Sets to fail on next persistance call * * @return void */ public static function failNextPersistanceCall() { static::$failNextPersistanceCall = true; } /** * Create a token instance. * * @return TokenInterface */ public function createTokenInstance() { $token = new Token(); return $token; } /** * Load a token from a persistent storage. * * @param string $uid * * @return \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface */ public function loadTokenByUid($uid) { } /** * Create or update a activity to a persistent storage. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface $token * @param bool $saveChildElements * * @return $this */ public function store(TokenInterface $token, $saveChildElements = false) { } /** * Persists instance and token data when a token arrives to an activity * * @param ActivityInterface $activity * @param TokenInterface $token * * @return mixed */ public function persistActivityActivated(ActivityInterface $activity, TokenInterface $token) { $instanceRepository = $token->getInstance()->getProcess()->getRepository()->createExecutionInstanceRepository(); $instanceRepository->persistInstanceUpdated($token->getInstance()); if (static::$failNextPersistanceCall) { static::$failNextPersistanceCall = false; throw new Exception('Failure expected when activity persists'); } } /** * Persists instance and token data when a token within an activity change to error state * * @param ActivityInterface $activity * @param TokenInterface $token * * @return mixed */ public function persistActivityException(ActivityInterface $activity, TokenInterface $token) { $instanceRepository = $token->getInstance()->getProcess()->getRepository()->createExecutionInstanceRepository(); $instanceRepository->persistInstanceUpdated($token->getInstance()); } /** * Persists instance and token data when a token is completed within an activity * * @param ActivityInterface $activity * @param TokenInterface $token * * @return mixed */ public function persistActivityCompleted(ActivityInterface $activity, TokenInterface $token) { $instanceRepository = $token->getInstance()->getProcess()->getRepository()->createExecutionInstanceRepository(); $instanceRepository->persistInstanceUpdated($token->getInstance()); } /** * Persists instance and token data when a token is closed by an activity * * @param ActivityInterface $activity * @param TokenInterface $token * * @return mixed */ public function persistActivityClosed(ActivityInterface $activity, TokenInterface $token) { $instanceRepository = $token->getInstance()->getProcess()->getRepository()->createExecutionInstanceRepository(); $instanceRepository->persistInstanceUpdated($token->getInstance()); } /** * Get persist calls * * @return int */ public function getPersistCalls() { return $this->persistCalls; } /** * Reset persist calls */ public function resetPersistCalls() { $this->persistCalls = 0; } /** * Persists instance and token data when a token arrives in a throw event * * @param ThrowEventInterface $event * @param TokenInterface $token * * @return mixed */ public function persistThrowEventTokenArrives(ThrowEventInterface $event, TokenInterface $token) { $this->persistCalls++; } /** * Persists instance and token data when a token is consumed in a throw event * * @param ThrowEventInterface $endEvent * @param TokenInterface $token * * @return mixed */ public function persistThrowEventTokenConsumed(ThrowEventInterface $endEvent, TokenInterface $token) { $this->persistCalls++; } /** * Persists instance and token data when a token is passed in a throw event * * @param ThrowEventInterface $endEvent * @param TokenInterface $token * * @return mixed */ public function persistThrowEventTokenPassed(ThrowEventInterface $endEvent, TokenInterface $token) { $this->persistCalls++; } /** * Persists instance and token data when a token arrives in a gateway * * @param GatewayInterface $exclusiveGateway * @param TokenInterface $token * * @return mixed */ public function persistGatewayTokenArrives(GatewayInterface $exclusiveGateway, TokenInterface $token) { $this->persistCalls++; } /** * Persists instance and token data when a token is consumed in a gateway * * @param GatewayInterface $exclusiveGateway * @param TokenInterface $token * * @return mixed */ public function persistGatewayTokenConsumed(GatewayInterface $exclusiveGateway, TokenInterface $token) { $this->persistCalls++; } /** * Persists instance and token data when a token is passed in a gateway * * @param GatewayInterface $exclusiveGateway * @param TokenInterface $token * * @return mixed */ public function persistGatewayTokenPassed(GatewayInterface $exclusiveGateway, TokenInterface $token) { $this->persistCalls++; } /** * Persists instance and token data when a token arrives in a catch event * * @param CatchEventInterface $intermediateCatchEvent * @param TokenInterface $token * * @return mixed */ public function persistCatchEventTokenArrives(CatchEventInterface $intermediateCatchEvent, TokenInterface $token) { $this->persistCalls++; } /** * Persists instance and token data when a token is consumed in a catch event * * @param CatchEventInterface $intermediateCatchEvent * @param TokenInterface $token * * @return mixed */ public function persistCatchEventTokenConsumed(CatchEventInterface $intermediateCatchEvent, TokenInterface $token) { $this->persistCalls++; } /** * Persists instance and token data when a token is passed in a catch event * * @param CatchEventInterface $intermediateCatchEvent * @param Collection $consumedTokens * * @return mixed */ public function persistCatchEventTokenPassed(CatchEventInterface $intermediateCatchEvent, Collection $consumedTokens) { $this->persistCalls++; } /** * Persists instance and token data when a message arrives to a catch event * * @param CatchEventInterface $intermediateCatchEvent * @param TokenInterface $token */ public function persistCatchEventMessageArrives(CatchEventInterface $intermediateCatchEvent, TokenInterface $token) { $this->persistCalls++; } /** * Persists instance and token data when a message is consumed in a catch event * * @param CatchEventInterface $intermediateCatchEvent * @param TokenInterface $token */ public function persistCatchEventMessageConsumed(CatchEventInterface $intermediateCatchEvent, TokenInterface $token) { $this->persistCalls++; } /** * Persists tokens that triggered a Start Event * * @param StartEventInterface $startEvent * @param CollectionInterface $tokens */ public function persistStartEventTriggered(StartEventInterface $startEvent, CollectionInterface $tokens) { } /** * Persists instance and token data when a token is consumed in a event based gateway * * @param \ProcessMaker\Nayra\Contracts\Bpmn\EventBasedGatewayInterface $eventBasedGateway * @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface $passedToken * @param \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface $consumedTokens * * @return mixed */ public function persistEventBasedGatewayActivated(EventBasedGatewayInterface $eventBasedGateway, TokenInterface $passedToken, CollectionInterface $consumedTokens) { } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Models/Repository.php
tests/ProcessMaker/Test/Models/Repository.php
<?php namespace ProcessMaker\Test\Models; use ProcessMaker\Nayra\Contracts\Repositories\StorageInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; use ProcessMaker\Nayra\RepositoryTrait; use ProcessMaker\Test\Models\CallActivity; use ProcessMaker\Test\Models\ExecutionInstance; use ProcessMaker\Test\Models\FormalExpression; use ProcessMaker\Test\Models\TestOneClassWithEmptyConstructor; use ProcessMaker\Test\Models\TestTwoClassWithArgumentsConstructor; /** * Repository */ class Repository implements RepositoryInterface { use RepositoryTrait; /** * Create instance of FormalExpression. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\FormalExpressionInterface */ public function createFormalExpression() { return new FormalExpression(); } /** * Create instance of CallActivity. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\CallActivityInterface */ public function createCallActivity() { return new CallActivity(); } /** * Create a execution instance repository. * * @return \ProcessMaker\Test\Models\ExecutionInstanceRepository */ public function createExecutionInstanceRepository() { return new ExecutionInstanceRepository(); } /** * Create a test class * * @return TestOneClassWithEmptyConstructor */ public function createTestOne() { return new TestOneClassWithEmptyConstructor(); } /** * Create a test class with parameters * * @param mixed $field1 * @param mixed $field2 * * @return TestTwoClassWithArgumentsConstructor */ public function createTestTwo($field1, $field2) { return new TestTwoClassWithArgumentsConstructor($field1, $field2); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Models/FormalExpression.php
tests/ProcessMaker/Test/Models/FormalExpression.php
<?php namespace ProcessMaker\Test\Models; use DateInterval; use DateTime; use Exception; use ProcessMaker\Nayra\Bpmn\FormalExpressionTrait; use ProcessMaker\Nayra\Bpmn\Models\DatePeriod; use ProcessMaker\Nayra\Contracts\Bpmn\FormalExpressionInterface; use ProcessMaker\Test\Models\TestBetsy; /** * FormalExpression implementation */ class FormalExpression implements FormalExpressionInterface { use FormalExpressionTrait; /** * Get the body of the Expression. * * @return string */ public function getBody() { return $this->getProperty(FormalExpressionInterface::BPMN_PROPERTY_BODY); } /** * Get the type that this Expression returns when evaluated. * * @return string */ public function getEvaluatesToType() { return $this->getProperty(FormalExpressionInterface::BPMN_PROPERTY_EVALUATES_TO_TYPE_REF); } /** * Get the expression language. * * @return string */ public function getLanguage() { return $this->getProperty(FormalExpressionInterface::BPMN_PROPERTY_LANGUAGE); } /** * Invoke the format expression. * * @param mixed $data * * @return string */ public function __invoke($data) { $expression = $this->getProperty(FormalExpressionInterface::BPMN_PROPERTY_BODY); $test = new TestBetsy($data, $expression); return $this->getDateExpression() ?: $this->getCycleExpression() ?: $this->getDurationExpression() ?: $test->call(); } /** * Verify if the expression is a date. * * @return bool */ private function isDateExpression() { $expression = $this->getProperty(FormalExpressionInterface::BPMN_PROPERTY_BODY); try { $date = new DateTime($expression); } catch (Exception $e) { return false; } return $date !== false; } /** * Verify if the expression is a cycle. * * @return bool */ private function isCycleExpression() { $expression = $this->getProperty(FormalExpressionInterface::BPMN_PROPERTY_BODY); try { $cycle = new DatePeriod($expression); } catch (Exception $e) { return false; } return $cycle !== false; } /** * Verify if the expression is a duration. * * @return bool */ private function isDurationExpression() { $expression = $this->getProperty(FormalExpressionInterface::BPMN_PROPERTY_BODY); try { $interval = new DateInterval($expression); } catch (Exception $e) { return false; } return $interval !== false; } /** * Set the body of the Expression. * * @param string $body */ public function setBody($body) { $this->setProperty(FormalExpressionInterface::BPMN_PROPERTY_BODY, $body); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Models/CallActivity.php
tests/ProcessMaker/Test/Models/CallActivity.php
<?php namespace ProcessMaker\Test\Models; use ProcessMaker\Nayra\Bpmn\ActivitySubProcessTrait; use ProcessMaker\Nayra\Bpmn\Events\ActivityActivatedEvent; use ProcessMaker\Nayra\Bpmn\Events\ActivityClosedEvent; use ProcessMaker\Nayra\Bpmn\Events\ActivityCompletedEvent; use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; use ProcessMaker\Nayra\Contracts\Bpmn\CallActivityInterface; /** * This activity will raise an exception when executed. */ class CallActivity implements CallActivityInterface { use ActivitySubProcessTrait; /** * Array map of custom event classes for the bpmn element. * * @return array */ protected function getBpmnEventClasses() { return [ ActivityInterface::EVENT_ACTIVITY_ACTIVATED => ActivityActivatedEvent::class, ActivityInterface::EVENT_ACTIVITY_COMPLETED => ActivityCompletedEvent::class, ActivityInterface::EVENT_ACTIVITY_CLOSED => ActivityClosedEvent::class, ]; } /** * Get the called element by the activity. * * @return \ProcessMaker\Nayra\Contracts\Bpmn\CallableElementInterface */ public function getCalledElement() { return $this->getProperty(CallActivityInterface::BPMN_PROPERTY_CALLED_ELEMENT); } /** * Set the called element by the activity. * * @param \ProcessMaker\Nayra\Contracts\Bpmn\CallableElementInterface|string $callableElement * * @return $this */ public function setCalledElement($callableElement) { $this->setProperty(CallActivityInterface::BPMN_PROPERTY_CALLED_ELEMENT, $callableElement); return $this; } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Models/ExecutionInstance.php
tests/ProcessMaker/Test/Models/ExecutionInstance.php
<?php namespace ProcessMaker\Test\Models; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; use ProcessMaker\Nayra\Engine\ExecutionInstanceTrait; /** * Execution instance for the engine. */ class ExecutionInstance implements ExecutionInstanceInterface { use ExecutionInstanceTrait; /** * Initialize a token class with unique id. */ protected function initToken() { $this->setId(uniqid()); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false
ProcessMaker/nayra
https://github.com/ProcessMaker/nayra/blob/19d721d6bd27f80d33288125488b244e83b6e191/tests/ProcessMaker/Test/Models/ExecutionInstanceRepository.php
tests/ProcessMaker/Test/Models/ExecutionInstanceRepository.php
<?php namespace ProcessMaker\Test\Models; use ProcessMaker\Nayra\Contracts\Bpmn\ParticipantInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; use ProcessMaker\Nayra\Contracts\Repositories\ExecutionInstanceRepositoryInterface; use ProcessMaker\Nayra\Contracts\Repositories\StorageInterface; /** * Execution Instance Repository. */ class ExecutionInstanceRepository implements ExecutionInstanceRepositoryInterface { /** * Array to simulate a storage of execution instances. * * @var array */ private static $data = []; /** * Load an execution instance from a persistent storage. * * @param string $uid * @param StorageInterface $storage * * @return null|ExecutionInstanceInterface */ public function loadExecutionInstanceByUid($uid, StorageInterface $storage) { if (empty(self::$data) || empty(self::$data[$uid])) { return; } $data = self::$data[$uid]; $instance = $this->createExecutionInstance(); $process = $storage->getProcess($data['processId']); $process->addInstance($instance); $dataStore = $storage->getFactory()->createDataStore(); $dataStore->setData($data['data']); $instance->setId($uid); $instance->setProcess($process); $instance->setDataStore($dataStore); $process->getTransitions($storage->getFactory()); //Load tokens: foreach ($data['tokens'] as $tokenInfo) { $token = $storage->getFactory()->getTokenRepository()->createTokenInstance(); $token->setProperties($tokenInfo); $element = $storage->getElementInstanceById($tokenInfo['elementId']); $element->addToken($instance, $token); } return $instance; } /** * Set the test data to be loaded. * * @param array $data */ public function setRawData(array $data) { self::$data = $data; } /** * Get instance data * * @param $instanceId * * @return array Data */ public function getInstanceData($instanceId) { return static::$data[$instanceId]['data']; } /** * Creates an execution instance. * * @return \ProcessMaker\Test\Models\ExecutionInstance */ public function createExecutionInstance() { return new ExecutionInstance(); } /** * Persists instance's data related to the event Process Instance Created * * @param ExecutionInstanceInterface $instance * * @return mixed */ public function persistInstanceCreated(ExecutionInstanceInterface $instance) { $id = $instance->getId(); self::$data[$id]['data'] = $instance->getDataStore()->getData(); } /** * Persists instance's data related to the event Process Instance Completed * * @param ExecutionInstanceInterface $instance * * @return mixed */ public function persistInstanceCompleted(ExecutionInstanceInterface $instance) { $id = $instance->getId(); self::$data[$id]['data'] = $instance->getDataStore()->getData(); } /** * Persists collaboration between two instances. * * @param ExecutionInstanceInterface $target Target instance * @param ParticipantInterface $targetParticipant Participant related to the target instance * @param ExecutionInstanceInterface $source Source instance * @param ParticipantInterface $sourceParticipant */ public function persistInstanceCollaboration(ExecutionInstanceInterface $target, ParticipantInterface $targetParticipant, ExecutionInstanceInterface $source, ParticipantInterface $sourceParticipant) { } /** * Persists instance data related to the event Process Instance Completed * * @param ExecutionInstanceInterface $instance * * @return mixed */ public function persistInstanceUpdated(ExecutionInstanceInterface $instance) { $id = $instance->getId(); self::$data[$id]['data'] = $instance->getDataStore()->getData(); } }
php
Apache-2.0
19d721d6bd27f80d33288125488b244e83b6e191
2026-01-05T05:04:52.897638Z
false