/** * {@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 enter(VirtualExecution $execution) { $engine = $execution->getEngine(); $name = $this->getStringValue($this->name, $execution->getExpressionContext()); $engine->debug('Execute expression in service task "{task}"', ['task' => $name]); $result = $this->getValue($this->expression, $execution->getExpressionContext()); if ($this->resultVariable !== NULL) { $execution->setVariable($this->resultVariable, $result); } $engine->notify(new TaskExecutedEvent($name, new DelegateExecution($execution), $engine)); $this->leave($execution); }
/** * {@inheritdoc} */ public function executeCommand(ProcessEngine $engine) { $def = $engine->getRepositoryService()->createProcessDefinitionQuery()->processDefinitionId($this->definitionId)->findOne(); $definition = $def->getModel(); $startNode = $definition->findNode($this->startNodeId); $process = new VirtualExecution(UUID::createRandom(), $engine, $definition); $process->setBusinessKey($this->businessKey); $process->setNode($startNode); foreach (unserialize($this->variables) as $k => $v) { $process->setVariable($k, $v); } $engine->registerExecution($process); $engine->info('Started {process} using process definition "{key}" ({id})', ['process' => (string) $process, 'key' => $def->getKey(), 'id' => (string) $def->getId()]); $process->execute($startNode); return $process->getId(); }
/** * Pass all variables given to the execution setting them in the executions's scope. * * @param VirtualExecution $execution * @param array $variables */ protected function passVariablesToExecution(VirtualExecution $execution, array $variables) { foreach ($variables as $k => $v) { $execution->setVariable($k, $v); } }