Wrapper method for MongoCollection::save().

This method will dispatch preSave and postSave events.

@see http://php.net/manual/en/mongocollection.remove.php
@param array $a       Document to save
@param array $options
@return array|boolean
482170
public function save(array &$a, array $options = [])
    {
        if ($this->eventManager->hasListeners(Events::preSave)) {
            $eventArgs = new EventArgs($this, $a, $options);
            $this->eventManager->dispatchEvent(Events::preSave, $eventArgs);
            $a = $eventArgs->getData();
            $options = $eventArgs->getOptions();
        }

        $result = $this->doSave($a, $options);

        if ($this->eventManager->hasListeners(Events::postSave)) {
            $eventArgs = new MutableEventArgs($this, $result);
            $this->eventManager->dispatchEvent(Events::postSave, $eventArgs);
            $result = $eventArgs->getData();
        }

        return $result;
    }
47195
public function afterSave($event, $entity, $options)
    {
        $fields = $this->getFieldList();
        $storedToSave = [];
        foreach ($fields as $field => $data) {
            if ($this->_ifUploaded($entity, $field)) {
                if ($this->_uploadFile($entity, $field)) {
                    if (!key_exists($field, $this->_savedFields)) {
                        $this->_savedFields[$field] = true;
                        $storedToSave[] = $this->_setUploadColumns($entity, $field);
                    }
                }
            }
        }
        foreach ($storedToSave as $toSave) {
            $event->subject()->save($toSave);
        }
        $this->_savedFields = [];
    }
609863
public static function saveAs($file, $options = [])
    {
        if (!($file instanceof UploadedFile)) {
            $file = UploadedFile::getInstanceByName($file);
        }
        $options['file'] = $file;
        $model = new static($options);
        return $model->save() ? $model : false;
    }
73420
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options) {
		$fields = $this->_getMappedFields();

		foreach ($fields as $map => $field) {
			if (!$entity->get($map)) {
				continue;
			}
			$val = $entity->get($map);
			$entity->set($field, $this->_encode($val));
		}
	}
539639
public function saveWithoutTimestamps(array $options = [])
    {
        $this->timestamps = false; // don't update updated_at
        $this->save($options);

        $this->timestamps = true; // forgetting this may result in unexpected behavior
    }
560671
protected function doSave(array &$a, array $options = array())
    {
        if (isset($a['_id'])) {
            return $this->doUpdate(array('_id' => $a['_id']), $a, $options);
        } else {
            return $this->doInsert($a, $options);
        }
    }
849958
public function insertOne($document, $options = [])
    {
        $objectDatas = $this->hydrator->unhydrate($document);

        $stream = $objectDatas["stream"];
        unset($objectDatas["stream"]);

        if (!isset($objectDatas["filename"])) {
            $filename = stream_get_meta_data($stream)["uri"];
        } else {
            $filename = $objectDatas["filename"];
        }

        unset($objectDatas["filename"]);

        $id = $this->bucket->uploadFromStream($filename, $stream, $objectDatas);
        $data['_id'] = $id;

        $data["stream"] = $this->bucket->openDownloadStream($data['_id']);
        $this->hydrator->hydrate($document, $data, true);

        $this->documentManager->setObjectState($document, ObjectManager::OBJ_MANAGED);
        $this->cacheObject($document);

        return true;
    }
1135155
public function save(array $rules = array(),
        array $customMessages = array(),
        array $options = array(),
        Closure $beforeSave = null,
        Closure $afterSave = null
    ) {
        return $this->internalSave($rules, $customMessages, $options, $beforeSave, $afterSave, false);
    }
765249
public function beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)
    {
        parent::beforeSave($event, $entity, $options);

        list($width, $height) = getimagesize($entity->path);
        $entity->size = compact('width', 'height');
    }
751150
public function save(array $options = array())
    {
        $data = $this->encode($options);

        if (($result = @file_put_contents($this->_path, $data)) === false) {
            throw SaveException::create($this->_path);
        }

        return $this;
    }
802545
public function deleteDocument($collection, $id, array $options = [])
    {
        $this->setOptions($options);
        $doc = new Document($this->client, $this->database, $collection);
        $doc->setHeaders($this->getHeaders());
        $rs = $doc->delete($id);
        $this->checkResponse($rs);
        unset($rs['_curl_info']);

        return $rs;
    }
567612
public function delete($collectionName, $condition, $options = [])
    {
        $batchOptions = [];
        foreach (['bypassDocumentValidation'] as $name) {
            if (isset($options[$name])) {
                $batchOptions[$name] = $options[$name];
                unset($options[$name]);
            }
        }

        $this->document = [];
        $this->addDelete($condition, $options);
        $result = $this->executeBatch($collectionName, $batchOptions);

        return $result['result'];
    }
97569
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options = null)
    {
        if ($entity->isNew()) {
            snapshot();
        }
    }
496383
public function save(array $options = [])
    {
        return DB::transaction(function() use ($options) {
            $result = parent::save($options);

            foreach ($this->autofilledRelations as $relationship => $relations) {
                if (!empty($relations)) {
                    $this->$relationship()->sync((array)$this->prepForSync($relations));
                }
            }

            return $result;
        });
    }
683516
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) : void
    {
        EventManager::instance()->dispatch(new Event(
            (string)EventName::MODEL_AFTER_SAVE(),
            $this,
            ['entity' => $entity, 'options' => ['current_user' => User::getCurrentUser()]]
        ));
    }
479060
protected function convertWriteTimeout(array $options)
    {
        if (version_compare(phpversion('mongo'), '1.4.0', '<')) {
            return $options;
        }

        if (isset($options['wTimeout']) && ! isset($options['wTimeoutMS'])) {
            $options['wTimeoutMS'] = $options['wTimeout'];
            unset($options['wTimeout']);
        }

        return $options;
    }
87982
public function save($image, $options)
    {
        $image = $this->saveToString($image, $options);
        return $this->saveFromString($image, $options);
    }