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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
<?php
namespace Basho\Riak\Command\Builder;
use Basho\Riak;
use Basho\Riak\Command;
class UpdateSet extends Command\Builder implements Command\BuilderInterface
{
use LocationTrait;
protected $add_all = [];
protected $remove_all = [];
protected $context = '';
public function add($element)
{
settype($element, 'string');
$this->add_all[] = $element;
return $this;
}
public function remove($element)
{
settype($element, 'string');
$this->remove_all[] = $element;
return $this;
}
public function withContext($context)
{
$this->context = $context;
return $this;
}
public function getAddAll()
{
return $this->add_all;
}
public function getRemoveAll()
{
return $this->remove_all;
}
public function getContext()
{
return $this->context;
}
public function build()
{
$this->validate();
return new Command\DataType\Set\Store($this);
}
public function validate()
{
$this->required('Bucket');
$count_add = count($this->add_all);
$count_remove = count($this->remove_all);
if ($count_add + $count_remove < 1) {
throw new Exception('At least one element to add or remove needs to be defined.');
}
if ($count_remove) {
$this->required('Location');
$this->required('Context');
}
}
}