Sokil\Mongo\Document::merge PHP Method

merge() public method

public merge ( array $data ) : Document
$data array
return Document
    public function merge(array $data)
    {
        if ($this->isStored()) {
            foreach ($data as $fieldName => $value) {
                $this->set($fieldName, $value);
            }
        } else {
            parent::merge($data);
        }
        return $this;
    }

Usage Example

Esempio n. 1
0
 public function insert(array $document)
 {
     if (!$this->isValidationEnabled) {
         self::$validator->merge($document);
         $isValid = self::$validator->isValid();
         self::$validator->reset();
         if (!$isValid) {
             throw new InvalidDocumentException('Document is invalid on batch insert');
         }
     }
     $this->add($document);
     return $this;
 }