You are here

protected function KeyvalueMongodb::getObject in MongoDB 8

Prepares an object for insertion.

4 calls to KeyvalueMongodb::getObject()
KeyvalueMongodb::set in src/KeyvalueMongodb.php
Saves a value for a given key.
KeyvalueMongodb::setIfNotExists in src/KeyvalueMongodb.php
Saves a value for a given key if it does not exist yet.
KeyvalueMongodb::setWithExpire in src/KeyvalueMongodb.php
Saves a value for a given key with a time to live.
KeyvalueMongodb::setWithExpireIfNotExists in src/KeyvalueMongodb.php
Sets a value for a given key with a time to live if it does not yet exist.

File

src/KeyvalueMongodb.php, line 53

Class

KeyvalueMongodb
This class holds a MongoDB key-value backend.

Namespace

Drupal\mongodb

Code

protected function getObject($key, $value, $expire = NULL) {
  $scalar = is_scalar($value);
  $object = array(
    '_id' => (string) $key,
    'value' => $scalar ? $value : serialize($value),
    'scalar' => $scalar,
  );
  if (!empty($expire)) {
    $object['expire'] = new \MongoDate(REQUEST_TIME + $expire);
  }
  return $object;
}