Skip to content

Commit

Permalink
Copy ValueExporter to this package for 4.0 compat
Browse files Browse the repository at this point in the history
See #225
Symfony 2.3 doesn't have this yet, copy it here for now.
  • Loading branch information
barryvdh committed Nov 14, 2014
1 parent f0e9450 commit 5eb06e0
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
81 changes: 81 additions & 0 deletions src/DataCollector/Util/ValueExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/*
* This file is a copy of Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter
* https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php
*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Barryvdh\Debugbar\DataCollector\Util;

/**
* @author Bernhard Schussek <[email protected]>
*/
class ValueExporter
{
/**
* Converts a PHP value to a string.
*
* @param mixed $value The PHP value
* @param int $depth only for internal usage
* @param bool $deep only for internal usage
*
* @return string The string representation of the given value
*/
public function exportValue($value, $depth = 1, $deep = false)
{
if (is_object($value)) {
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ISO8601));
}

return sprintf('Object(%s)', get_class($value));
}

if (is_array($value)) {
if (empty($value)) {
return '[]';
}

$indent = str_repeat(' ', $depth);

$a = array();
foreach ($value as $k => $v) {
if (is_array($v)) {
$deep = true;
}
$a[] = sprintf('%s => %s', $k, $this->exportValue($v, $depth + 1, $deep));
}

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)) {
return sprintf('Resource(%s#%d)', get_resource_type($value), $value);
}

if (null === $value) {
return 'null';
}

if (false === $value) {
return 'false';
}

if (true === $value) {
return 'true';
}

return (string) $value;
}
}
2 changes: 1 addition & 1 deletion src/DataCollector/ViewCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Barryvdh\Debugbar\DataCollector;

use Barryvdh\Debugbar\DataCollector\Util\ValueExporter;
use DebugBar\Bridge\Twig\TwigCollector;
use Illuminate\View\View;
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;

class ViewCollector extends TwigCollector
{
Expand Down

0 comments on commit 5eb06e0

Please sign in to comment.