You are here

function ds_var_export in Display Suite 6.3

Same name and namespace in other branches
  1. 6 includes/ds.tools.inc \ds_var_export()
  2. 6.2 includes/ds.tools.inc \ds_var_export()

Nice var exporter, based on Views.

2 calls to ds_var_export()
ds_export in includes/ds.tools.inc
Export functionality.
ds_features_export_render in includes/ds.features.inc
Implementation of hook_features_export_render().

File

includes/ds.tools.inc, line 360
Tools for Display suite like export & import.

Code

function ds_var_export($var, $prefix = '  ', $init = TRUE, $indent = '  ') {
  if (is_array($var)) {
    if (empty($var)) {
      $output = 'array()';
    }
    else {
      $prefix .= '  ';
      $old = $indent;
      $indent .= '  ';
      $output = "array(\n";
      foreach ($var as $key => $value) {
        $output .= "{$indent}'{$key}' => " . ds_var_export($value, $prefix, FALSE, $indent) . ",\n";
      }
      $indent = $old;
      $output .= "{$indent})";
    }
  }
  elseif (is_bool($var)) {
    $output = $var ? 'TRUE' : 'FALSE';
  }
  elseif (is_string($var) && strpos($var, "\n") !== FALSE) {

    // Replace line breaks in strings with a token for replacement
    // at the very end. This protects multi-line strings from
    // unintentional indentation.
    $var = str_replace("\n", "***BREAK***", $var);
    $output = var_export($var, TRUE);
  }
  else {
    $output = var_export($var, TRUE);
  }
  if ($init) {
    $output = str_replace("***BREAK***", "\n", $output);
  }
  return $output;
}