Elastica\Document::remove PHP Метод

remove() публичный Метод

public remove ( string $key )
$key string
    public function remove($key)
    {
        if (!$this->has($key)) {
            throw new InvalidException("Field {$key} does not exist");
        }
        unset($this->_data[$key]);
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * @group unit
  */
 public function testSerializedData()
 {
     $data = '{"user":"******"}';
     $document = new Document(1, $data);
     $this->assertFalse($document->has('user'));
     try {
         $document->get('user');
         $this->fail('User field should not be available');
     } catch (InvalidException $e) {
         $this->assertTrue(true);
     }
     try {
         $document->remove('user');
         $this->fail('User field should not be available for removal');
     } catch (InvalidException $e) {
         $this->assertTrue(true);
     }
     try {
         $document->set('name', 'shawn');
         $this->fail('Document should not allow to set new data');
     } catch (InvalidException $e) {
         $this->assertTrue(true);
     }
 }