/** * Mint a new Object instance with a json encoded string * * @param mixed $data * * @return $this */ public function buildJsonObject($data) { $this->object = new RObject(); $this->object->setData($data); $this->object->setContentType(Http::CONTENT_TYPE_JSON); return $this; }
/** * @depends testFetchConflicted */ public function testResolveConflict() { $object = new Riak\Object('some_resolved_data'); $object->setVclock(static::$vclock); $command = (new Command\Builder\StoreObject(static::$riak))->withObject($object)->buildLocation(static::$key, 'test', static::LEVELDB_BUCKET_TYPE)->build(); $response = $command->execute(); $this->assertEquals('204', $response->getCode()); }
public function testStoreObjectWithIndexes() { $object = new RObject('person'); $object->addValueToIndex('lucky_numbers_int', 42); $object->addValueToIndex('lucky_numbers_int', 64); $object->addValueToIndex('lastname_bin', 'Knuth'); $command = (new Command\Builder\StoreObject(static::$riak))->withObject($object)->buildLocation(static::$key, 'Users', static::LEVELDB_BUCKET_TYPE)->build(); $response = $command->execute(); $this->assertEquals('204', $response->getCode()); }
public function getData() { return $this->object->getData(); }
/** * @expectedException InvalidArgumentException */ public function testInvalidDataTypeForIntIndex() { $data = new \StdClass(); $data->woot = 'sauce'; $object = new Object($data); $object->addValueToIndex('foo_int', 'bar'); }
/** * Retrieve a sibling by sibling number. * * @param integer $i - Sibling number. * @param integer $r - R-Value. Wait until this many partitions * have responded before returning to client. * @return Object. */ public function getSibling($i, $r = null) { # Use defaults if not specified. $r = $this->bucket->getR($r); # Run the request... $vtag = $this->siblings[$i]; $params = array('r' => $r, 'vtag' => $vtag); $url = Utils::buildRestPath($this->client, $this->bucket, $this->key, null, $params); $response = Utils::httpRequest('GET', $url); # Respond with a new object... $obj = new Object($this->client, $this->bucket, $this->key); $obj->jsonize = $this->jsonize; $obj->populate($response, array(200)); return $obj; }
<?php include 'bootstrap.php'; use Basho\Riak; use Basho\Riak\Api; use Basho\Riak\Command; $add = false; $name = isset($_POST['name']) ? $_POST['name'] : null; $email = isset($_POST['email']) ? $_POST['email'] : null; $id = !empty($email) ? substr(md5($email), 0, 5) : ''; if ($name && $email) { $result = (new Command\Builder\FetchObject($riak))->buildLocation($id, BUCKET_CUST, TYPE)->build()->execute(); $object = new Riak\Object(['id_s' => $id, 'email_s' => $email, 'name_s' => $name]); $object->setContentType(Api\Http::CONTENT_TYPE_JSON); if (!$result->isNotFound() && null !== $result->getObject()->getVclock()) { $object->setVclock($result->getObject()->getVclock()); } $result = (new Command\Builder\StoreObject($riak))->withObject($object)->buildLocation($id, BUCKET_CUST, TYPE)->build()->execute(); if ($result->isSuccess()) { $add = true; } } header('Location: index.php?add=' . $add);
/** * Search a secondary index * * @author Eric Stevens <*****@*****.**> * @param string $indexName - The name of the index to search * @param string $indexType - The type of index ('int' or 'bin') * @param string|int $startOrExact * @param string|int optional $end * @param bool optional $dedupe - whether to eliminate duplicate entries if any * @return array of Links */ public function indexSearch($indexName, $indexType, $startOrExact, $end = null, $dedupe = false) { $url = Utils::buildIndexPath($this->client, $this, strtolower("{$indexName}_{$indexType}"), $startOrExact, $end, null); //print_r($url); $response = Utils::httpRequest('GET', $url); $obj = new Object($this->client, $this, null); //var_dump($response); //print_r($response); $obj->populate($response, array(200)); if (!$obj->exists()) { throw new Exception("Error searching index."); } $data = $obj->getData(); $keys = array_map("urldecode", $data["keys"]); $seenKeys = array(); foreach ($keys as $id => &$key) { if ($dedupe) { if (isset($seenKeys[$key])) { unset($keys[$id]); continue; } $seenKeys[$key] = true; } $key = new Link($this->name, $key); $key->client = $this->client; } return $keys; }