Skip to content

Commit

Permalink
[HttpKernel] tweaked value exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 28, 2014
1 parent 3f297ea commit 1cda2d4
Showing 1 changed file with 12 additions and 5 deletions.
Expand Up @@ -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));
Expand All @@ -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)) {
Expand Down

0 comments on commit 1cda2d4

Please sign in to comment.