/**
  * {@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();
 }
Esempio n. 2
0
 protected function setUp()
 {
     parent::setUp();
     $this->eventDispatcher = new EventDispatcher();
     $this->conn = static::createConnection('bpm_', $this->eventDispatcher);
     static::migrateDirectoryUp($this->conn, __DIR__ . '/../../migration');
     $logger = NULL;
     if (NULL !== ($logLevel = $this->getLogLevel())) {
         $stderr = fopen('php://stderr', 'wb');
         $levels = array_change_key_case(Logger::getLevels(), CASE_UPPER);
         $logger = new Logger('BPMN');
         $logger->pushHandler(new StreamHandler($stderr, $levels[strtoupper($logLevel)]));
         $logger->pushProcessor(new PsrLogMessageProcessor());
         fwrite($stderr, "\n");
         fwrite($stderr, sprintf("TEST CASE: %s\n", $this->getName()));
         // 			$this->conn$conn->setDebug(true);
         // 			$this->conn->setLogger($logger);
     }
     $this->messageHandlers = [];
     $this->serviceTaskHandlers = [];
     // Provide message handler subscriptions.
     $this->eventDispatcher->connect(function (MessageThrownEvent $event) {
         $def = $this->repositoryService->createProcessDefinitionQuery()->processDefinitionId($event->execution->getProcessDefinitionId())->findOne();
         $key = $def->getKey();
         $id = $event->execution->getActivityId();
         if (isset($this->messageHandlers[$key][$id])) {
             return $this->messageHandlers[$key][$id]($event);
         }
     });
     $this->eventDispatcher->connect(function (TaskExecutedEvent $event) {
         $execution = $this->runtimeService->createExecutionQuery()->executionId($event->execution->getExecutionId())->findOne();
         $key = $execution->getProcessDefinition()->getKey();
         $id = $event->execution->getActivityId();
         if (isset($this->serviceTaskHandlers[$key][$id])) {
             $this->serviceTaskHandlers[$key][$id]($event->execution);
         }
     });
     // Allow for assertions in expressions, e.g. #{ @test.assertEquals(2, processVariable) }
     $this->eventDispatcher->connect(function (CreateExpressionContextEvent $event) {
         $event->access->setVariable('@test', $this);
     });
     $this->delegateTasks = new DelegateTaskRegistry();
     $this->processEngine = new ProcessEngine($this->conn, $this->eventDispatcher, new ExpressionContextFactory());
     $this->processEngine->setDelegateTaskFactory($this->delegateTasks);
     $this->processEngine->setLogger($logger);
     $scheduler = new TestJobScheduler($this->processEngine);
     $this->jobExecutor = new JobExecutor($this->processEngine, $scheduler);
     $this->processEngine->setJobExecutor($this->jobExecutor);
     $this->repositoryService = $this->processEngine->getRepositoryService();
     $this->runtimeService = $this->processEngine->getRuntimeService();
     $this->taskService = $this->processEngine->getTaskService();
     $this->historyService = $this->processEngine->getHistoryService();
     $this->managementService = $this->processEngine->getManagementService();
     if ($this->typeInfo === NULL) {
         $this->typeInfo = new ReflectionTypeInfo(new \ReflectionClass(get_class($this)));
     }
     foreach ($this->typeInfo->getMethods() as $method) {
         if (!$method->isPublic() || $method->isStatic()) {
             continue;
         }
         foreach ($method->getAnnotations() as $anno) {
             if ($anno instanceof MessageHandler) {
                 $this->messageHandlers[$anno->processKey][$anno->value] = [$this, $method->getName()];
             }
             if ($anno instanceof ServiceTaskHandler) {
                 $this->serviceTaskHandlers[$anno->processKey][$anno->value] = [$this, $method->getName()];
             }
         }
     }
 }