/** * {@inheritdoc} */ public function enter(VirtualExecution $execution) { $engine = $execution->getEngine(); $name = $this->getStringValue($this->name, $execution->getExpressionContext()); $engine->debug('Evaluate <{language}> script task "{task}"', ['language' => $this->language, 'task' => $name]); if ($this->scriptResource !== NULL) { $process = $engine->getRepositoryService()->createProcessDefinitionQuery()->processDefinitionId($execution->getProcessModel()->getId())->findOne(); $deployment = $engine->getRepositoryService()->createDeploymentQuery()->deploymentId($process->getDeploymentId())->findOne(); $resource = $deployment->findResourceById($process->getResourceId()); $file = str_replace('./', '', dirname($resource->getName()) . '/' . $this->scriptResource); $script = '?>' . $deployment->findResource($file)->getContents(); } else { $script = $this->script; } // Isolate scope to prevent manipulation of local / instance variables: $callback = function (DelegateExecution $execution, $script) { return eval($script); }; if (method_exists($callback, 'bindTo')) { $callback = $callback->bindTo(NULL, NULL); } $result = $callback(new DelegateExecution($execution), $script); if ($this->resultVariable !== NULL) { $execution->setVariable($this->resultVariable, $result); } $engine->notify(new TaskExecutedEvent($name, new DelegateExecution($execution), $engine)); $this->leave($execution); }
/** * {@inheritdoc} */ public function processSignal(VirtualExecution $execution, $signal, array $variables = [], array $delegation = []) { $engine = $execution->getEngine(); $engine->notify(new ActivityCompletedEvent($execution->getNode()->getId(), $execution, $engine)); $node = $execution->getProcessModel()->findNode($delegation['nodeId']); $engine->notify(new ActivityStartedEvent($node->getId(), $execution, $engine)); $this->delegateSignal($execution, $signal, $variables, $delegation); }
/** * {@inheritdoc} */ public function enter(VirtualExecution $execution) { $model = $execution->getProcessModel(); $execution->getEngine()->debug('Starting sub process "{process}"', ['process' => $this->getStringValue($this->name, $execution->getExpressionContext())]); $startNode = $model->findNode($this->startNodeId); if (!$startNode->getBehavior() instanceof NoneStartEventBehavior) { throw new \RuntimeException(sprintf('Cannot start sub process %s ("%s") because it is missing start node %s', $execution->getNode()->getId(), $this->getStringValue($this->name, $execution->getExpressionContext()), $this->startNodeId)); } $execution->waitForSignal(); $sub = $execution->createNestedExecution($model, $startNode, true, false); $sub->execute($startNode); }
public function processSignal(VirtualExecution $execution, $signal, array $variables = [], array $delegation = []) { $startNode = $execution->getProcessModel()->findNode($this->startNodeId); $root = $execution->getScope(); $scope = $this->findScopeActivity($execution); if (!$this->isInterrupting()) { return $scope->leaveConcurrent($root, $startNode); } // Kill all remaining concurrent executions within the scope activity: foreach ($root->findChildExecutions() as $child) { $child->terminate(false); } $scope->clearEventSubscriptions($root, $scope->getActivityId()); $root->setNode($this->findScopeNode($root)); $root->setActive(false); $root->waitForSignal(); $sub = $root->createExecution(false); $sub->setNode($startNode); $sub->waitForSignal(); $sub->getEngine()->notify(new ActivityCanceledEvent($this->attachedTo, $sub, $sub->getEngine())); // Delegate received signal to event sub process start event. $sub->signal($signal, $variables); }
/** * Collect all boundary events connected to the activity of the given execution. * * @param VirtualExecution $execution * @return array<Node> */ public function findAttachedBoundaryActivities(VirtualExecution $execution) { $model = $execution->getProcessModel(); $activities = []; foreach ($model->findNodes() as $node) { $behavior = $node->getBehavior(); if ($behavior instanceof AbstractBoundaryActivity) { if ($this->activityId == $behavior->getAttachedTo()) { $activities[] = $node; } } } return $activities; }
/** * Delegate signal to a target node using the same execution. * * @param VirtualExecution $execution * @param string $signal * @param array $variables * @param array $delegation * @return boolean Returns true if the signal could be delegated. */ protected function delegateSignal(VirtualExecution $execution, $signal, array $variables, array $delegation) { if (empty($delegation['nodeId'])) { return false; } $node = $execution->getProcessModel()->findNode($delegation['nodeId']); $execution->getEngine()->debug('Delegating signal <{signal}> to {node}', ['signal' => $signal === NULL ? 'NULL' : $signal, 'node' => (string) $node]); $execution->setNode($node); $execution->waitForSignal(); $execution->signal($signal, $variables); return true; }
/** * @param VirtualExecution $execution * @return AbstractScopeActivity */ public function findScopeActivity(VirtualExecution $execution) { return $execution->getProcessModel()->findNode($this->attachedTo)->getBehavior(); }