Esempio n. 1
0
 /**
  * @param \Riak\Client\Core\Message\DataType\GetRequest $request
  *
  * @return \Riak\Client\Core\Message\DataType\GetResponse
  */
 public function send(Request $request)
 {
     $response = new GetResponse();
     $httpRequest = $this->createHttpRequest($request);
     try {
         $httpResponse = $this->client->send($httpRequest);
         $code = $httpResponse->getStatusCode();
     } catch (RequestException $e) {
         if ($e->getCode() == 404 && $request->notfoundOk) {
             return $response;
         }
         throw $e;
     }
     if (!isset($this->validResponseCodes[$code])) {
         throw RiakTransportException::unexpectedStatusCode($code);
     }
     $json = $httpResponse->json();
     $context = isset($json['context']) ? $json['context'] : null;
     $value = $json['value'];
     $type = $json['type'];
     $response->type = $type;
     $response->context = $context;
     $response->value = $this->opConverter->fromArray($type, $value);
     return $response;
 }
Esempio n. 2
0
 /**
  * @param \Riak\Client\Core\Message\Bucket\PutRequest $request
  *
  * @return \Riak\Client\Core\Message\Bucket\PutResponse
  */
 public function send(Request $request)
 {
     $response = new PutResponse();
     $httpRequest = $this->createHttpRequest($request);
     $httpResponse = $this->client->send($httpRequest);
     $code = $httpResponse->getStatusCode();
     if (!isset($this->validResponseCodes[$code])) {
         throw RiakTransportException::unexpectedStatusCode($code);
     }
     return $response;
 }
Esempio n. 3
0
 /**
  * @param \Riak\Client\Core\Message\MapReduce\MapReduceRequest $request
  *
  * @return \Riak\Client\Core\Message\MapReduce\MapReduceResponse
  */
 public function send(Request $request)
 {
     $response = new MapReduceResponse();
     $httpRequest = $this->createHttpRequest($request);
     $httpResponse = $this->client->send($httpRequest);
     $code = $httpResponse->getStatusCode();
     if (!isset($this->validResponseCodes[$code])) {
         throw RiakTransportException::unexpectedStatusCode($code);
     }
     $multipartIterator = new MultipartResponseIterator($httpResponse);
     $mapReduceIterator = new HttpMapReduceResponseIterator($multipartIterator);
     $response->iterator = $mapReduceIterator;
     return $response;
 }
Esempio n. 4
0
 /**
  * @param \Riak\Client\Core\Message\Bucket\GetRequest $request
  *
  * @return \Riak\Client\Core\Message\Bucket\GetResponse
  */
 public function send(Request $request)
 {
     $httpRequest = $this->createHttpRequest($request);
     $httpResponse = $this->client->send($httpRequest);
     $code = $httpResponse->getStatusCode();
     if (!isset($this->validResponseCodes[$code])) {
         throw RiakTransportException::unexpectedStatusCode($code);
     }
     $json = $httpResponse->json();
     $props = $json['props'];
     $response = $this->createGetResponse($props);
     $response->name = $request->bucket;
     return $response;
 }
Esempio n. 5
0
 /**
  * @param \Riak\Client\Core\Message\Kv\DeleteRequest $request
  *
  * @return \Riak\Client\Core\Message\Kv\DeleteResponse
  */
 public function send(Request $request)
 {
     $httpRequest = $this->createHttpRequest($request);
     $response = new DeleteResponse();
     $httpResponse = $this->client->send($httpRequest);
     $code = $httpResponse->getStatusCode();
     if (!isset($this->validResponseCodes[$code])) {
         throw RiakTransportException::unexpectedStatusCode($code);
     }
     $contentList = $this->getRiakContentList($httpResponse);
     $vClock = $httpResponse->getHeader('X-Riak-Vclock');
     $response->vClock = $vClock;
     $response->contentList = $contentList;
     return $response;
 }
Esempio n. 6
0
 /**
  * @param \Riak\Client\Core\Message\Bucket\ListRequest $request
  *
  * @return \Riak\Client\Core\Message\Bucket\ListResponse
  */
 public function send(Request $request)
 {
     $response = new ListResponse();
     $httpRequest = $this->createHttpRequest($request);
     $httpResponse = $this->client->send($httpRequest);
     $code = $httpResponse->getStatusCode();
     if (!isset($this->validResponseCodes[$code])) {
         throw RiakTransportException::unexpectedStatusCode($code);
     }
     $json = $httpResponse->json();
     $iterator = array_map(function ($item) {
         return new \ArrayIterator([$item]);
     }, $json['buckets']);
     $response->iterator = new \ArrayIterator($iterator);
     return $response;
 }
Esempio n. 7
0
 /**
  * @param \Riak\Client\Core\Message\Kv\PutRequest $request
  *
  * @return \Riak\Client\Core\Message\Kv\PutResponse
  */
 public function send(Request $request)
 {
     $httpRequest = $this->createHttpRequest($request);
     $httpResponse = $this->client->send($httpRequest);
     $code = $httpResponse->getStatusCode();
     $response = new PutResponse();
     if (!isset($this->validResponseCodes[$code])) {
         throw RiakTransportException::unexpectedStatusCode($code);
     }
     $contentList = $this->getRiakContentList($httpResponse);
     $vClock = $httpResponse->getHeader('X-Riak-Vclock');
     $key = null;
     if ($httpResponse->hasHeader('Location')) {
         $location = $httpResponse->getHeader('Location');
         $key = substr($location, strrpos($location, '/') + 1);
     }
     $response->key = $key;
     $response->vClock = $vClock;
     $response->contentList = $contentList;
     return $response;
 }
Esempio n. 8
0
 /**
  * @param \Riak\Client\Core\Message\Kv\GetRequest $request
  *
  * @return \Riak\Client\Core\Message\Kv\GetResponse
  */
 public function send(Request $request)
 {
     $httpRequest = $this->createHttpRequest($request);
     $response = new GetResponse();
     try {
         $httpResponse = $this->client->send($httpRequest);
         $code = $httpResponse->getStatusCode();
     } catch (RequestException $e) {
         if ($e->getCode() == 404 && $request->notfoundOk) {
             return $response;
         }
         throw $e;
     }
     if (!isset($this->validResponseCodes[$code])) {
         throw RiakTransportException::unexpectedStatusCode($code);
     }
     $contentList = $this->getRiakContentList($httpResponse);
     $vClock = $httpResponse->getHeader('X-Riak-Vclock');
     $response->vClock = $vClock;
     $response->contentList = $contentList;
     return $response;
 }