Skip to content

Commit 5eb06e0

Browse files
committed
Copy ValueExporter to this package for 4.0 compat
See #225 Symfony 2.3 doesn't have this yet, copy it here for now.
1 parent f0e9450 commit 5eb06e0

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is a copy of Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter
5+
* https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php
6+
*
7+
* This file is part of the Symfony package.
8+
*
9+
* (c) Fabien Potencier <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Barryvdh\Debugbar\DataCollector\Util;
16+
17+
/**
18+
* @author Bernhard Schussek <[email protected]>
19+
*/
20+
class ValueExporter
21+
{
22+
/**
23+
* Converts a PHP value to a string.
24+
*
25+
* @param mixed $value The PHP value
26+
* @param int $depth only for internal usage
27+
* @param bool $deep only for internal usage
28+
*
29+
* @return string The string representation of the given value
30+
*/
31+
public function exportValue($value, $depth = 1, $deep = false)
32+
{
33+
if (is_object($value)) {
34+
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
35+
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ISO8601));
36+
}
37+
38+
return sprintf('Object(%s)', get_class($value));
39+
}
40+
41+
if (is_array($value)) {
42+
if (empty($value)) {
43+
return '[]';
44+
}
45+
46+
$indent = str_repeat(' ', $depth);
47+
48+
$a = array();
49+
foreach ($value as $k => $v) {
50+
if (is_array($v)) {
51+
$deep = true;
52+
}
53+
$a[] = sprintf('%s => %s', $k, $this->exportValue($v, $depth + 1, $deep));
54+
}
55+
56+
if ($deep) {
57+
return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat(' ', $depth - 1));
58+
}
59+
60+
return sprintf("[%s]", implode(', ', $a));
61+
}
62+
63+
if (is_resource($value)) {
64+
return sprintf('Resource(%s#%d)', get_resource_type($value), $value);
65+
}
66+
67+
if (null === $value) {
68+
return 'null';
69+
}
70+
71+
if (false === $value) {
72+
return 'false';
73+
}
74+
75+
if (true === $value) {
76+
return 'true';
77+
}
78+
79+
return (string) $value;
80+
}
81+
}

src/DataCollector/ViewCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Barryvdh\Debugbar\DataCollector;
44

5+
use Barryvdh\Debugbar\DataCollector\Util\ValueExporter;
56
use DebugBar\Bridge\Twig\TwigCollector;
67
use Illuminate\View\View;
7-
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
88

99
class ViewCollector extends TwigCollector
1010
{

0 commit comments

Comments
 (0)