Пример #1
0
 /**
  * Parse the message
  *
  * @param  mixed $message
  * @return NamedCommand
  */
 private function parseMessage($message)
 {
     try {
         return $this->messageParser->parse($message);
     } catch (MessageParserException $e) {
         $this->logger->error('Error parsing or executing command', ['exception' => $e->getMessage()]);
         $errorMessage = $this->messageFactory->buildMessage([$this->getMessageUser($e)], $e);
         if (!$errorMessage) {
             $this->logger->warning('Message could not be generated');
             return null;
         }
         $this->messageSender->send($errorMessage, $message);
         return null;
     }
 }
 /**
  * Commit transaction.
  *
  * @throws CommitException
  * @throws NoRunningTransactionException
  */
 public function commit()
 {
     if (!$this->transactionRunning) {
         throw new NoRunningTransactionException();
     }
     try {
         foreach ($this->messages as $message) {
             $this->messageSender->send($message[0], $message[1]);
         }
     } catch (\Exception $e) {
         throw new CommitException('Error during commit', 0, $e);
     }
     $this->messages = [];
     $this->transactionRunning = false;
 }
 /**
  * Handle an event.
  *
  * @param EventInterface $event
  * @param Context        $context
  *
  * @return void
  */
 public function handle(EventInterface $event, Context $context = null)
 {
     if (!$event instanceof UnableToCreateUserEvent) {
         return;
     }
     $this->logger->info('Send message', ['user' => $event->getUser()->getName(), 'type' => $event->getName()]);
     $messageContext = null;
     if ($context) {
         $messageContext = $this->messageFinder->findByReference($context->getValue());
     }
     $message = $this->messageFactory->buildMessage([$event->getUser()], $event);
     if (!$message) {
         $this->logger->warning('Message could not be generated');
         return;
     }
     $this->messageSender->send($message, $messageContext ? $messageContext->getSource() : null);
 }
 /**
  * @param  GameResult        $gameResult
  * @param  ApplicationUser[] $users
  * @param  mixed             $messageContext
  * @return void
  */
 private function sendMessage(GameResult $gameResult, array $users = [], $messageContext = null)
 {
     $message = $this->messageFactory->buildMessage($users, $gameResult);
     if (!$message) {
         $this->logger->warning('Message could not be generated');
         return;
     }
     $this->messageSender->send($message, $messageContext);
 }