Exemple #1
0
 /**
  * @param Response $response
  * @param Request $request
  * @return mixed|null
  * @throws \Wookieb\ZorroRPC\Exception\FormatException
  */
 private function obtainResponse(Response $response, Request $request)
 {
     // woah, time to handle error
     if ($response->getType() === MessageTypes::ERROR) {
         $this->handleError($response, $request);
     }
     // check whether response type is suitable for request type
     if ($response->getType() !== self::$validResponseType[$request->getType()]) {
         $msg = sprintf('Invalid response type "%s" for request type "%s"', $response->getType(), $request->getType());
         throw new FormatException($msg, $response);
     }
     if (!MessageTypes::isResponseTypeWithResult($response->getType())) {
         return;
     }
     return $this->serializer->unserializeResult($request->getMethodName(), $response->getResultBody(), $response->getHeaders()->get('Content-Type'));
 }