Permalink
Browse files

[HttpKernel] tweaked value exporter

  • Loading branch information...
1 parent 3f297ea commit 1cda2d43c4455ee5df5ece20cd73b14d63f8a85a @fabpot fabpot committed Feb 28, 2014
Showing with 12 additions and 5 deletions.
  1. +12 −5 src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php
@@ -19,12 +19,12 @@ class ValueExporter
/**
* Converts a PHP value to a string.
*
- * @param mixed $value The PHP value
- * @param integer $depth The depth of the value to export
+ * @param mixed $value The PHP value
+ * @param integer $depth The depth of the value to export (only for internal usage)
*
* @return string The string representation of the given value
*/
- public function exportValue($value, $depth = 0)
+ public function exportValue($value, $depth = 1, $deep = false)
{
if (is_object($value)) {
return sprintf('Object(%s)', get_class($value));
@@ -39,10 +39,17 @@ public function exportValue($value, $depth = 0)
$a = array();
foreach ($value as $k => $v) {
- $a[] = sprintf('%s %s => %s', $indent, $k, $this->exportValue($v, $depth + 1));
+ if (is_array($v)) {
+ $deep = true;
+ }
+ $a[] = sprintf('%s => %s', $k, $this->exportValue($v, $depth + 1, $deep));
}
- return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), $indent);
+ if ($deep) {
+ return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat(' ', $depth - 1));
+ }
+
+ return sprintf("[%s]", implode(', ', $a));
}
if (is_resource($value)) {

0 comments on commit 1cda2d4

Please sign in to comment.