- <?php
- * @file
- * Miscellaneous functions.
- */
-
- * Backdrop-friendly var_export().
- *
- * @param $var
- * The variable to export.
- * @param $prefix
- * A prefix that will be added at the beginning of every lines of the output.
- *
- * @return
- * The variable exported in a way compatible to Backdrop's coding standards.
- */
- function backdrop_var_export($var, $prefix = '') {
- if (is_array($var)) {
- if (empty($var)) {
- $output = 'array()';
- }
- else {
- $output = "array(\n";
-
- $export_keys = array_values($var) != $var;
- foreach ($var as $key => $value) {
- $output .= ' ' . ($export_keys ? backdrop_var_export($key) . ' => ' : '') . backdrop_var_export($value, ' ') . ",\n";
- }
- $output .= ')';
- }
- }
- elseif (is_bool($var)) {
- $output = $var ? 'TRUE' : 'FALSE';
- }
- elseif (is_string($var)) {
- if (strpos($var, "\n") !== FALSE || strpos($var, "'") !== FALSE) {
-
-
-
- $var = str_replace(array('\\', '"', "\n", "\r", "\t"), array('\\\\', '\"', '\n', '\r', '\t'), $var);
- $output = '"' . $var . '"';
- }
- else {
- $output = "'" . $var . "'";
- }
- }
- elseif (is_object($var) && get_class($var) === 'stdClass') {
-
-
-
-
- $output = '(object) ' . backdrop_var_export((array) $var, $prefix);
- }
- else {
- $output = var_export($var, TRUE);
- }
-
- if ($prefix) {
- $output = str_replace("\n", "\n$prefix", $output);
- }
-
- return $output;
- }