You are here

public static function MongoCollectionFactory::castValue in MongoDB 8

Cast a value according to a SQL type.

2 calls to MongoCollectionFactory::castValue()
Condition::translateCondition in src/Entity/Condition.php
ContentEntityStorage::getDataToSave in src/Entity/ContentEntityStorage.php
Collect the translations of an entity for saving.

File

src/MongoCollectionFactory.php, line 134
Definition of Drupal\mongodb\MongodbBundle.

Class

MongoCollectionFactory
Creates mongo collections based on settings.

Namespace

Drupal\mongodb

Code

public static function castValue($sql_type, $value) {
  if (is_array($value)) {
    $value = array_values($value);
  }
  switch ($sql_type) {
    case 'int':
    case 'serial':
      return is_array($value) ? array_map('intval', $value) : intval($value);
    case 'float':
      return is_array($value) ? array_map('floatval', $value) : floatval($value);
    default:
      return $value;
  }
}