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

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

public set ( string $key, mixed $value )
$key string
$value mixed
    public function set($key, $value)
    {
        if (!is_array($this->_data)) {
            throw new InvalidException('Document data is serialized data. Data creation is forbidden.');
        }
        $this->_data[$key] = $value;
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function toDocument(Model $model, Document $document)
 {
     $mapping = ['city' => 'city', 'state' => 'state', 'country' => 'country', 'zip_code' => 'zip_code'];
     foreach ($mapping as $field => $key) {
         $document->set($key, $model->{$field});
     }
     if (!empty($model->lat) && !empty($model->lon)) {
         $document->set('location', ['lon' => $model->lon, 'lat' => $model->lat]);
     }
     $fullAddress = [];
     if (!empty($model->city)) {
         $fullAddress[] = $model->city;
     }
     if (!empty($model->state)) {
         $fullAddress[] = $model->state;
     }
     if (!empty($model->zip_code)) {
         $fullAddress[] = $model->zip_code;
     }
     if (!empty($model->country)) {
         $fullAddress[] = $model->country;
     }
     $document->set('full_address', implode(', ', $fullAddress));
     return $document;
 }
All Usage Examples Of Elastica\Document::set