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

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

public get ( string $key ) : mixed
$key string
Результат mixed
    public function get($key)
    {
        if (!$this->has($key)) {
            throw new InvalidException("Field {$key} does not exist");
        }
        return $this->_data[$key];
    }

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);
     }
 }