-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from basho/issue65
Issue65 and some cleanup.
- Loading branch information
Showing
5 changed files
with
155 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
/** | ||
* Riak PHP Client | ||
* | ||
|
@@ -17,12 +18,10 @@ | |
* @category Basho | ||
* @copyright Copyright (c) 2013 Basho Technologies, Inc. and contributors. | ||
*/ | ||
|
||
namespace Basho\Riak; | ||
|
||
use Basho\Riak\Exception, | ||
Basho\Riak\Link, | ||
Basho\Riak\Object, | ||
Basho\Riak\Utils; | ||
use Basho\Riak\Link; | ||
|
||
/** | ||
* Bucket | ||
|
@@ -32,13 +31,18 @@ | |
*/ | ||
class Bucket | ||
{ | ||
/** | ||
* @var Riak|null | ||
*/ | ||
protected $client = null; | ||
|
||
/** | ||
* Construct a Bucket object | ||
* | ||
* @param \Basho\Riak\Riak $client Riak Client object | ||
* @param Riak $client Riak Client object | ||
* @param string $name Bucket name | ||
*/ | ||
public function __construct($client, $name) | ||
public function __construct(Riak $client, $name) | ||
{ | ||
$this->client = $client; | ||
$this->name = $name; | ||
|
@@ -60,17 +64,12 @@ public function getName() | |
/** | ||
* Get the R-value for this bucket | ||
* | ||
* Returns the buckets R-value If it is set, | ||
* otherwise return the R-value for the client. | ||
* Returns the buckets R-value If it is set, otherwise return the R-value for the client. | ||
* | ||
* @return integer | ||
* @return int | ||
*/ | ||
public function getR($r = null) | ||
public function getR() | ||
{ | ||
if ($r != null) { | ||
return $r; | ||
} | ||
|
||
if ($this->r != null) { | ||
return $this->r; | ||
} | ||
|
@@ -87,6 +86,7 @@ public function getR($r = null) | |
* @see \Basho\Riak\Bucket::get() | ||
* @see \Basho\Riak\Bucket::getBinary() | ||
* @param integer $r - The new R-value. | ||
* | ||
* @return $this | ||
*/ | ||
public function setR($r) | ||
|
@@ -99,17 +99,12 @@ public function setR($r) | |
/** | ||
* Get the W-value for this bucket | ||
* | ||
* If it is set for this bucket, otherwise return | ||
* the W-value for the client. | ||
* If it is set for this bucket, otherwise return the W-value for the client. | ||
* | ||
* @return integer | ||
* @return int | ||
*/ | ||
public function getW($w) | ||
public function getW() | ||
{ | ||
if ($w != null) { | ||
return $w; | ||
} | ||
|
||
if ($this->w != null) { | ||
return $this->w; | ||
} | ||
|
@@ -123,6 +118,7 @@ public function getW($w) | |
* See setR(...) for more information. | ||
* | ||
* @param integer $w - The new W-value. | ||
* | ||
* @return $this | ||
*/ | ||
public function setW($w) | ||
|
@@ -135,17 +131,12 @@ public function setW($w) | |
/** | ||
* Get the DW-value for this bucket | ||
* | ||
* If it is set for this bucket, otherwise return | ||
* the DW-value for the client. | ||
* If it is set for this bucket, otherwise return the DW-value for the client. | ||
* | ||
* @return integer | ||
* @return int | ||
*/ | ||
public function getDW($dw) | ||
public function getDW() | ||
{ | ||
if ($dw != null) { | ||
return $dw; | ||
} | ||
|
||
if ($this->dw != null) { | ||
return $this->dw; | ||
} | ||
|
@@ -159,6 +150,7 @@ public function getDW($dw) | |
* See setR(...) for more information. | ||
* | ||
* @param integer $dw - The new DW-value | ||
* | ||
* @return $this | ||
*/ | ||
public function setDW($dw) | ||
|
@@ -173,6 +165,7 @@ public function setDW($dw) | |
* | ||
* @param string $key - Name of the key. (default NULL) | ||
* @param object $data - The data to store. (default NULL) | ||
* | ||
* @return Object | ||
*/ | ||
public function newObject($key = null, $data = null) | ||
|
@@ -191,6 +184,7 @@ public function newObject($key = null, $data = null) | |
* @param string $key - Name of the key. (default NULL) | ||
* @param object $data - The data to store. | ||
* @param string $content_type - The content type of the object. (default 'application/json') | ||
* | ||
* @return Object | ||
*/ | ||
public function newBinary($key = null, $data, $content_type = 'application/json') | ||
|
@@ -208,13 +202,13 @@ public function newBinary($key = null, $data, $content_type = 'application/json' | |
* | ||
* @param string $key - Name of the key. | ||
* @param int $r - R-Value of the request (defaults to bucket's R) | ||
* | ||
* @return Object | ||
*/ | ||
public function get($key, $r = null) | ||
{ | ||
$obj = new Object($this->client, $this, $key); | ||
$obj->jsonize = true; | ||
$r = $this->getR($r); | ||
|
||
return $obj->reload($r); | ||
} | ||
|
@@ -224,13 +218,13 @@ public function get($key, $r = null) | |
* | ||
* @param string $key - Name of the key. | ||
* @param int $r - R-Value of the request (defaults to bucket's R) | ||
* | ||
* @return Object | ||
*/ | ||
public function getBinary($key, $r = null) | ||
{ | ||
$obj = new Object($this->client, $this, $key); | ||
$obj->jsonize = false; | ||
$r = $this->getR($r); | ||
|
||
return $obj->reload($r); | ||
} | ||
|
@@ -245,6 +239,8 @@ public function getBinary($key, $r = null) | |
* only be used if you know what you are doing. | ||
* | ||
* @param integer $nval - The new N-Val. | ||
* | ||
* @return bool | ||
*/ | ||
public function setNVal($nval) | ||
{ | ||
|
@@ -270,6 +266,8 @@ public function getNVal() | |
* if you know what you are doing. | ||
* | ||
* @param boolean $bool - True to store and return conflicting writes. | ||
* | ||
* @return bool | ||
*/ | ||
public function setAllowMultiples($bool) | ||
{ | ||
|
@@ -293,6 +291,8 @@ public function getAllowMultiples() | |
* | ||
* @param string $key - Property to set. | ||
* @param mixed $value - Property value. | ||
* | ||
* @return bool | ||
*/ | ||
public function setProperty($key, $value) | ||
{ | ||
|
@@ -321,6 +321,9 @@ public function getProperty($key) | |
* This should only be used if you know what you are doing. | ||
* | ||
* @param array $props - An associative array of $key=>$value. | ||
* | ||
* @return bool | ||
* @throws Exception | ||
*/ | ||
public function setProperties($props) | ||
{ | ||
|
@@ -342,12 +345,15 @@ public function setProperties($props) | |
if ($status != 204) { | ||
throw new Exception("Error setting bucket properties."); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Retrieve an associative array of all bucket properties. | ||
* | ||
* @return Array | ||
* @throws Exception | ||
*/ | ||
public function getProperties() | ||
{ | ||
|
@@ -375,6 +381,7 @@ public function getProperties() | |
* Note: this operation is pretty slow. | ||
* | ||
* @return Array | ||
* @throws Exception | ||
*/ | ||
public function getKeys() | ||
{ | ||
|
@@ -390,19 +397,22 @@ public function getKeys() | |
} | ||
$keys = $obj->getData(); | ||
|
||
return array_map("urldecode", $keys["keys"]); | ||
return $keys["keys"]; | ||
} | ||
|
||
/** | ||
* Search a secondary index | ||
* | ||
* @author Eric Stevens <[email protected]> | ||
* @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 | ||
* @param bool $dedupe | ||
* | ||
* @return array of Links | ||
* @throws Exception | ||
*/ | ||
public function indexSearch($indexName, $indexType, $startOrExact, $end = null, $dedupe = false) | ||
{ | ||
|
@@ -416,7 +426,7 @@ public function indexSearch($indexName, $indexType, $startOrExact, $end = null, | |
throw new Exception("Error searching index."); | ||
} | ||
$data = $obj->getData(); | ||
$keys = array_map("urldecode", $data["keys"]); | ||
$keys = $data["keys"]; | ||
|
||
$seenKeys = array(); | ||
foreach ($keys as $id => &$key) { | ||
|
@@ -435,12 +445,15 @@ public function indexSearch($indexName, $indexType, $startOrExact, $end = null, | |
} | ||
|
||
/** | ||
* Check if a given key exists in a bucket | ||
* | ||
* @author Edgar Veiga <[email protected]> | ||
* @param string $key - The key to check | ||
* @return bool | ||
*/ | ||
* Check if a given key exists in a bucket | ||
* | ||
* @author Edgar Veiga <[email protected]> | ||
* | ||
* @param string $key - The key to check | ||
* | ||
* @return bool | ||
* @throws Exception | ||
*/ | ||
public function hasKey($key) | ||
{ | ||
$url = Utils::buildRestPath($this->client, $this, $key); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.