/**
  * @param RpcRequestInterface  $request
  * @param RpcResponseInterface $response
  */
 private function logResponseWithRequest(RpcRequestInterface $request, RpcResponseInterface $response)
 {
     $hash = spl_object_hash($response);
     if (in_array($hash, $this->loggedResponses, true)) {
         return;
     }
     if ($response->isSuccessful()) {
         $this->logger->info(sprintf('Method "%s" call was successful', $request->getMethod()), ['request_hash' => spl_object_hash($request)]);
         $this->logger->debug(sprintf("Response:\n%s", json_encode($response->getBody(), JSON_PRETTY_PRINT)), ['request_hash' => spl_object_hash($request)]);
     } else {
         $this->logger->info(sprintf('Method "%s" call was failed', $request->getMethod()), ['request_hash' => spl_object_hash($request)]);
         $this->logger->error(sprintf('ERROR %s: %s', $response->getError()->getCode(), $response->getError()->getMessage()), ['request_hash' => spl_object_hash($request)]);
     }
     $this->loggedResponses[] = $hash;
 }
예제 #2
0
 /**
  * @param RpcRequestInterface $request
  * @param string $id
  * @return static
  */
 public static function fromRpcRequest(RpcRequestInterface $request, $id)
 {
     return new static($request->getMethod(), $request->getParameters(), $id);
 }
예제 #3
0
 public static function emptyQueue(RpcRequestInterface $request)
 {
     $ex = new static(sprintf('Mock queue is empty while calling "%s"', $request->getMethod()));
     $ex->request = $request;
     return $ex;
 }
예제 #4
0
 public function getKey(RpcRequestInterface $request)
 {
     $data = ['method' => (string) $request->getMethod(), 'params' => json_decode(json_encode($request->getParameters()), true)];
     $stringData = json_encode($data);
     return $this->keyPrefix . sha1($stringData);
 }