summaryrefslogtreecommitdiff
path: root/includes/utility.inc
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-06-28 02:05:47 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-06-28 02:05:47 +0000
commit029e7b8828adbbe6c68d5f3809abaca5f704ad3c (patch)
treeb29753faf51ba176d45df01bfa184c05b5aaabb9 /includes/utility.inc
parent8ef7c6fb8db3e3100488968a532d0237ed350341 (diff)
downloadbrdo-029e7b8828adbbe6c68d5f3809abaca5f704ad3c.tar.gz
brdo-029e7b8828adbbe6c68d5f3809abaca5f704ad3c.tar.bz2
#838438 by Damien Tournoud, chx: Added basic tests for D6 => D7 upgrade path, and framework for further extending upgrade test coverage. W00t! :D
Diffstat (limited to 'includes/utility.inc')
-rw-r--r--includes/utility.inc59
1 files changed, 59 insertions, 0 deletions
diff --git a/includes/utility.inc b/includes/utility.inc
new file mode 100644
index 000000000..438389d12
--- /dev/null
+++ b/includes/utility.inc
@@ -0,0 +1,59 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Miscellaneous functions.
+ */
+
+/**
+ * Drupal-friendly var_export().
+ *
+ * @param $var
+ * The variable to export.
+ * @param $prefix
+ * A prefix that will be added at the begining of every lines of the output.
+ * @return
+ * The variable exported in a way compatible to Drupal's coding standards.
+ */
+function drupal_var_export($var, $prefix = '') {
+ if (is_array($var)) {
+ if (empty($var)) {
+ $output = 'array()';
+ }
+ else {
+ $output = "array(\n";
+ // Don't export keys if the array is non associative.
+ $export_keys = array_values($var) != $var;
+ foreach ($var as $key => $value) {
+ $output .= ' ' . ($export_keys ? drupal_var_export($key) . ' => ' : '') . drupal_var_export($value, ' ', FALSE) . ",\n";
+ }
+ $output .= ')';
+ }
+ }
+ else if (is_bool($var)) {
+ $output = $var ? 'TRUE' : 'FALSE';
+ }
+ else if (is_string($var)) {
+ $line_safe_var = str_replace("\n", '\n', $var);
+ if (strpos($var, "\n") !== FALSE || strpos($var, "'") !== FALSE) {
+ // If the string contains a line break or a single quote, use the
+ // double quote export mode. Encode backslash and double quotes and
+ // transform some common control characters.
+ $var = str_replace(array('\\', '"', "\n", "\r", "\t"), array('\\\\', '\"', '\n', '\r', '\t'), $var);
+ $output = '"' . $var . '"';
+ }
+ else {
+ $output = "'" . $var . "'";
+ }
+ }
+ else {
+ $output = var_export($var, TRUE);
+ }
+
+ if ($prefix) {
+ $output = str_replace("\n", "\n$prefix", $output);
+ }
+
+ return $output;
+}