Example #1
0
 /**
  * @param Envelope $envelope
  * @return Request
  * @throws Exception\InvalidJsonRpcVersion
  * @throws Exception\JsonParseError
  */
 protected function requestFromEnvelope(Envelope $envelope) : Request
 {
     if ($envelope->getHeader('jsonrpc') !== JsonRpcRequest::JSONRPC_VERSION) {
         throw new Exception\InvalidJsonRpcVersion();
     }
     if ($envelope->getContentEncoding() !== 'UTF-8' || $envelope->getContentType() !== 'application/json') {
         throw new Exception\InvalidJsonRpcRequest();
     }
     $payload = json_decode($envelope->getBody(), true);
     if (0 != json_last_error()) {
         throw new Exception\JsonParseError();
     }
     return new JsonRpcRequest($envelope->getExchangeName(), $envelope->getType(), $payload, $envelope->getCorrelationId(), $envelope->getRoutingKey(), (int) $envelope->getExpiration(), $envelope->getTimestamp());
 }