Basho\Riak\Object::removeValueFromIndex PHP Method

removeValueFromIndex() public method

public removeValueFromIndex ( $indexName, $value )
    public function removeValueFromIndex($indexName, $value)
    {
        if (!isset($this->indexes[$indexName])) {
            return $this;
        }
        $valuePos = array_search($value, $this->indexes[$indexName]);
        if ($valuePos !== false) {
            array_splice($this->indexes[$indexName], $valuePos, 1);
        }
        if (count($this->indexes[$indexName]) == 0) {
            unset($this->indexes[$indexName]);
        }
        return $this;
    }

Usage Example

Exemplo n.º 1
0
 public function testRemoveIndexes()
 {
     $data = new \StdClass();
     $data->woot = 'sauce';
     $headers = ['x-riak-index-foo_bin' => 'bar, baz', 'x-riak-index-foo_int' => '42, 50'];
     $object = new Object($data, $headers);
     $object->removeValueFromIndex("foo_int", 50);
     $object->removeValueFromIndex("foo_bin", 'baz');
     $object->removeValueFromIndex("foo_bin", 'bar');
     $indexes = $object->getIndexes();
     $this->assertNotEmpty($indexes);
     $this->assertEquals(1, count($indexes));
     $this->assertEquals([42], $indexes["foo_int"]);
 }