示例#1
0
 /** @test */
 public function shouldClearAllVariableValues()
 {
     Variables::clear();
     Variables::set('test1', '123');
     Variables::set('test2', '456');
     Variables::clear();
     $this->assertEquals([], Variables::all());
 }
 /**
  * @param ActionDto $dto
  * @return null
  */
 public function processAction(ActionDto $dto)
 {
     $name = $dto->get('name');
     $value = $dto->get('value');
     switch ((string) $value) {
         case 'increment':
             Variables::set($name, Variables::get($name) + 1);
             break;
         case 'decrement':
             Variables::set($name, Variables::get($name) - 1);
             break;
         default:
             Variables::set($name, $value);
     }
 }
 /**
  * @param RequestDto $dto
  * @return null
  */
 public function handler(RequestDto $dto)
 {
     // 4a. Timeout, exiting
     if ($this->coreProcessor->isMessageTimedOut($this->handlerId)) {
         $this->slackFacade->getSlackApi()->chatPostMessage($this->recipientId, 'Sorry, response timed out');
         $this->coreProcessor->removeTimedMessageHandler($this->handlerId);
         return;
     }
     // 4b. Processed. Setting variable.
     if ($this->coreProcessor->isMessageHandled($this->handlerId)) {
         $dto = $this->coreProcessor->getTimedMessageHandleResult($this->handlerId);
         if (null === $dto) {
             return;
         }
         $this->coreProcessor->removeTimedMessageHandler($this->handlerId);
         $response = $dto->get('text');
         Variables::set(Ar::get($this->dtoData, 'variable'), $response);
         // 5. Send "after" message
         $afterMessage = Ar::get($this->dtoData, 'messages.after');
         if (null !== $afterMessage) {
             $this->slackFacade->getSlackApi()->chatPostMessage($this->recipientId, $afterMessage);
         }
         // 6. Processing other actions.
         $afterActions = Ar::get($this->dtoData, 'after');
         if (0 === count($afterActions)) {
             return;
         }
         foreach ($afterActions as $afterAction) {
             $actionDto = $this->createActionDto();
             $this->populateActionDto($actionDto, $afterAction);
             $this->coreProcessor->processAction($actionDto);
         }
     }
 }
 /**
  * @param ActionDto $dto
  * @return null
  */
 public function processAction(ActionDto $dto)
 {
     Variables::set('flowcontrol.break', true);
 }