/** * @param SocketConnection $from * @param string $msg * @throws \Exception */ public function onMessage(SocketConnection $from, $msg) { try { if (!$this->connectionManager->hasConnection($from)) { throw new NotManagedConnectionException('Unknown Connection'); } if (null === ($payload = Payload::createFromJson($msg))) { throw new InvalidPayloadException(sprintf('Invalid payload received: "%s"', $msg)); } if (!in_array($payload->getEvent(), $this->allowedEvents)) { throw new InvalidEventCallException(sprintf('Unregistered event: "%s".', $payload->getEvent())); } $connection = $this->connectionManager->getConnection($from); $this->handle($connection, $payload); } catch (InvalidPayloadException $e) { $this->logger->debug($e->getMessage()); } catch (InvalidEventCallException $e) { $this->logger->debug($e->getMessage()); } catch (NotManagedConnectionException $e) { $this->logger->warning($e->getMessage()); } catch (\Exception $e) { $this->logger->error($e->getMessage()); throw new \RuntimeException('An error occurred during server runtime.', 500, $e); } }