Skip to content

Commit

Permalink
Merge pull request #98 from basho/issue65
Browse files Browse the repository at this point in the history
Issue65 and some cleanup.
  • Loading branch information
christophermancini committed Jun 10, 2015
2 parents 5ec7b8b + a3bc506 commit 8d14107
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 108 deletions.
95 changes: 54 additions & 41 deletions src/Basho/Riak/Bucket.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Riak PHP Client
*
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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')
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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()
{
Expand Down Expand Up @@ -375,6 +381,7 @@ public function getProperties()
* Note: this operation is pretty slow.
*
* @return Array
* @throws Exception
*/
public function getKeys()
{
Expand All @@ -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)
{
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/Basho/Riak/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
*/
class Link
{
/**
* @var Riak|null
*/
public $client = null;

/**
* Construct a Link object.
* @param string $bucket - The bucket name.
Expand Down Expand Up @@ -72,7 +77,7 @@ public function getBucket()

/**
* Set the bucket name of this link.
* @param string $name - The bucket name.
* @param $bucket
* @return $this
*/
public function setBucket($bucket)
Expand Down
Loading

0 comments on commit 8d14107

Please sign in to comment.