function _drush_variable_format

6.x variable.drush.inc _drush_variable_format($value, $format)
7.x variable.drush.inc _drush_variable_format($value, $format)
5.x variable.drush.inc _drush_variable_format($value, $format)
1 call to _drush_variable_format()
drush_variable_set in commands/core/variable.drush.inc
Command callback. Set a variable.

File

commands/core/variable.drush.inc, line 232

Code

function _drush_variable_format($value, $format) {
  if ($format == 'auto') {
    if (is_int($value)) {
      $format = 'integer';
    }
    elseif (($value == 'TRUE') || ($value == 'FALSE')) {
      $format = 'bool';
    }
  }

  // Now, we parse the object.
  switch ($format) {
    case 'integer':
      $value = (integer) $value;
      break;

    case 'bool':
    case 'boolean':
      if ($value == 'TRUE') {
        $value = TRUE;
      }
      elseif ($value == 'FALSE') {
        $value = FALSE;
      }
      else {
        $value = (bool) $value;
      }
      break;

    case 'json':
      $value = drush_json_decode($value);
      break;

    case 'yaml':
      $value = Yaml::parse($value);
      break;
  }
  return $value;
}