/**
  * @test
  */
 public function it_should_send_message()
 {
     $this->socketMessage = $this->socketMessage->reveal();
     $this->messageComposer->compose($this->socketMessage)->willReturn('binary');
     $this->stream->write('binary')->shouldBeCalledTimes(1);
     $this->streamHandler->sendMessage($this->socketMessage);
 }
Exemplo n.º 2
0
 /**
  * Enables listeners
  */
 public function run()
 {
     $actionsToRun = $this->actionsToRun;
     $streamHandler = $this->streamHandler;
     $this->stream->onData(function ($data) use($streamHandler, $actionsToRun) {
         $socketMessage = $streamHandler->handle($data);
         if (is_null($socketMessage)) {
             return;
         }
         foreach ($actionsToRun as $key => $callback) {
             if ($key === $socketMessage->getMessageType()->getType()) {
                 $callback($socketMessage);
                 return;
             }
         }
     });
 }
Exemplo n.º 3
0
 /**
  * Sends message to stream sever
  *
  * @param SocketMessage $socketMessage
  *
  * @return void
  * @throws DomainException
  */
 public function sendMessage(SocketMessage $socketMessage)
 {
     try {
         $binaryMessage = $this->messageComposer->compose($socketMessage);
         $this->stream->write($binaryMessage);
     } catch (\Exception $e) {
         $this->logger->critical('Error during send a message with ' . $socketMessage->getMessageType()->getType() . ' and id ' . $socketMessage->getCorrelationID() . '. Message Error: ' . $e->getMessage());
     }
 }
Exemplo n.º 4
0
 /**
  * Enables listeners
  */
 public function run()
 {
     $actionsToRun = $this->actionsToRun;
     $streamHandler = $this->streamHandler;
     $this->stream->onData(function ($data) use($streamHandler, $actionsToRun) {
         $socketMessages = $streamHandler->handle($data);
         if (sizeof($socketMessages) == 0) {
             return;
         }
         /** @var SocketMessage $socketMessage */
         foreach ($socketMessages as $socketMessage) {
             $messageType = $socketMessage->getMessageType()->getType();
             if (array_key_exists($messageType, $actionsToRun)) {
                 $callback = $actionsToRun[$messageType];
                 $callback($socketMessage);
             }
         }
     });
 }