本文整理汇总了PHP中MongoCollection::save方法的典型用法代码示例。如果您正苦于以下问题:PHP MongoCollection::save方法的具体用法?PHP MongoCollection::save怎么用?PHP MongoCollection::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doWrite
/**
* Write a message to the log.
*
* @param array $event Event data
* @return void
* @throws Zend\Log\Exception\RuntimeException
*/
protected function doWrite(array $event)
{
if (null === $this->mongoCollection) {
throw new RuntimeException('MongoCollection must be defined');
}
$this->mongoCollection->save($event, $this->saveOptions);
}
示例2: save
public function save($document)
{
$data = $this->objectFactory->marshal($document);
$this->mongoCollection->save($data);
$this->objectFactory->setId($document, $data['_id']);
return $this;
}
示例3: write
/**
* Write messages
*
* @return mixed|void
*/
public function write()
{
foreach ($this->messages as $message) {
$message['log'] = $this->format($message);
$this->collection->save($message);
}
}
示例4: persist
/**
* {@inheritDoc}
*/
public function persist(Persistable $doc)
{
$struc = $this->factory->desegregate($doc);
if (array_key_exists('id', $struc)) {
unset($struc['id']);
}
if (!is_null($doc->getId())) {
$struc['_id'] = $doc->getId();
}
$this->collection->save($struc);
$doc->setId($struc['_id']);
}
示例5: write
/**
* Write Session Data
*
* @param string $id
* Session Data ID
*
* @param string $data
* Data to Store
*
* @param integer $expires
* Expiration Timestamp
*
* @return boolean
* TRUE on success and FALSE on failure
*/
public function write($id, $data, $expires)
{
if (!empty($_SESSION)) {
$this->collection->save(array('_id' => $id, 'data' => eval(sprintf('return %s;', preg_replace(array('/\\w+::__set_state\\(/', '/\\)\\)/'), array(NULL, ')'), var_export($_SESSION, TRUE)))), 'serialized' => new \MongoBinData(gzcompress($data)), 'expires' => new \MongoDate(time() + $expires)));
}
return TRUE;
}
示例6: set
/**
* Save data to a the MongoDB collection
*
* @param integer $id
* @param array $data
* @param integer $lifetime
* @param mixed $tags
* @return boolean
*/
private function set($id, $data, $lifetime, $tags)
{
list($nowMicroseconds, $nowSeconds) = explode(' ', microtime());
$nowMicroseconds = intval($nowMicroseconds * 1000000);
//Convert from 'expressed in seconds' to complete microseconds
return $this->_collection->save(array('_id' => $id, 'd' => $data, 'created_at' => new \MongoDate($nowSeconds, $nowMicroseconds), 'expires_at' => is_numeric($lifetime) && intval($lifetime) !== 0 ? new \MongoDate($nowSeconds + $lifetime, $nowMicroseconds) : null, 't' => $tags, 'hits' => 0));
}
示例7: write
/**
* This writes to memory.
* After returning PHP will invoke SessionHandler::close.
*
* @param string $sessionId
* @param string $data Serialized shit
* @return boolean
*/
public function write($sessionId, $data)
{
$query = array("session-id" => $sessionId);
$toSave = array_merge($query, array("data" => $data, "time" => time()));
try {
$el = $this->collection->findOne($query);
if ($el === null) {
$result = $this->collection->save($toSave);
} else {
$result = $this->collection->update($query, $toSave);
}
return $result["ok"] == 1;
} catch (MongoCursorException $ex) {
return false;
}
}
示例8: doSave
/**
* Execute the save query.
*
* @see Collection::save()
* @param array $a
* @param array $options
* @return array|boolean
*/
protected function doSave(array &$a, array $options)
{
$options = isset($options['safe']) ? $this->convertWriteConcern($options) : $options;
$options = isset($options['wtimeout']) ? $this->convertWriteTimeout($options) : $options;
$options = isset($options['timeout']) ? $this->convertSocketTimeout($options) : $options;
return $this->mongoCollection->save($a, $options);
}
示例9: save
/**
* Will add or update an existing object with a matching _id
*
* @param type $value object to save
*/
public function save($value)
{
ValidatorsUtil::isNullOrEmpty($this->_mongoCollection, "Mongo collection isn't valid, have you set a collection?");
ValidatorsUtil::isNull($value, "Must have a valid object to insert in collection");
$this->_mongoCollection->save($value);
$this->_count = 0;
}
示例10: set
/**
* @param int $id
* @param array $data
* @param int $lifetime
* @param mixed $tags
* @return boolean
*/
public function set($id, $data, $lifetime, $tags)
{
$now = time();
// set the lifetime to 1 year if it is null
if (!$lifetime) {
$lifetime = 86400 * 365;
}
return $this->_collection->save(['_id' => $id, 'd' => $data, 'created_at' => $now, 'l' => $lifetime, 'expire' => $now + $lifetime, 't' => $tags]);
}
示例11: save
/**
* Saving record to the database
* @param boolean $validate Validate record before saving
* @param boolean $throw Throw an expcetion if an error occured
* @return boolean Operation success mark
* @throws \MongoAR\Exception If an error occured and $throw is set to TRUE
* @since 0.1
*/
public function save($validate = true, $throw = false)
{
if ($this->id) {
$this->document['_id'] = $this->id;
}
$response = $this->table->save($this->document);
$this->fetchId($this->document);
return $this->checkResponse($response, $throw);
}
示例12: storeData
/**
* {@inheritdoc}
*/
public function storeData($key, $data, $expiration)
{
if ($this->collection instanceof \MongoDB\Collection) {
$id = self::mapKey($key);
try {
$this->collection->replaceOne(['_id' => $id], ['_id' => $id, 'data' => serialize($data), 'expiration' => $expiration], ['upsert' => true]);
} catch (\MongoDB\Driver\Exception\BulkWriteException $ignored) {
// As of right now, BulkWriteException can be thrown by replaceOne in high-throughput environments where race conditions can occur
}
} else {
try {
$this->collection->save(['_id' => self::mapKey($key), 'data' => serialize($data), 'expiration' => $expiration]);
} catch (\MongoDuplicateKeyException $ignored) {
// Because it's Mongo, we might have had this problem because of a cache stampede
}
}
return true;
}
示例13: save
/**
* Write a profile to the mongo database
*
* @param array $profile Profiler Collected Data
* @return void
* @throws Exception\RuntimeException
*/
public function save(array $profile)
{
if (null === $this->mongoCollection) {
throw new Exception\RuntimeException('MongoCollection must be defined');
}
if ($this->hostname !== 'all') {
$profile['report']['hostname'] = $this->hostname;
}
$this->mongoCollection->save($profile, $this->saveOptions);
}
示例14: doWrite
/**
* Write a message to the log.
*
* @param array $event Event data
* @return void
* @throws Zend\Log\Exception\RuntimeException
*/
protected function doWrite(array $event)
{
if (null === $this->mongoCollection) {
throw new RuntimeException('MongoCollection must be defined');
}
if (isset($event['timestamp']) && $event['timestamp'] instanceof DateTime) {
$event['timestamp'] = new MongoDate($event['timestamp']->getTimestamp());
}
$this->mongoCollection->save($event, $this->saveOptions);
}
示例15: testGroup2
public function testGroup2()
{
$this->object->save(array("a" => 2));
$this->object->save(array("b" => 5));
$this->object->save(array("a" => 1));
$keys = array();
$initial = array("count" => 0);
$reduce = "function (obj, prev) { prev.count++; }";
$g = $this->object->group($keys, $initial, $reduce);
$this->assertEquals(3, $g['count']);
}