1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
<?php
namespace Basho\Riak\Command\Builder;
use Basho\Riak\Api\Http;
use Basho\Riak\Object;
/**
* Allows easy code sharing for Object getters / setters within the Command Builders
*
* @author Christopher Mancini <cmancini at basho d0t com>
*/
trait ObjectTrait
{
/**
* @var \Basho\Riak\Object|null
*/
protected $object = NULL;
/**
* @return Object|null
*/
public function getObject()
{
return $this->object;
}
/**
* Mint a new Object instance with supplied params and attach it to the Command
*
* @param string $data
* @param array $headers
*
* @return $this
*/
public function buildObject($data = NULL, $headers = NULL)
{
$this->object = new Object($data, $headers);
return $this;
}
/**
* Attach an already instantiated Object to the Command
*
* @param \Basho\Riak\Object $object
*
* @return $this
*/
public function withObject(Object $object)
{
$this->object = $object;
return $this;
}
/**
* Mint a new Object instance with a json encoded string
*
* @param mixed $data
*
* @return $this
*/
public function buildJsonObject($data)
{
$this->object = new Object();
$this->object->setData($data);
$this->object->setContentType(Http::CONTENT_TYPE_JSON);
return $this;
}
}