[VarDumper] edge case fixes
This commit is contained in:
parent
15dfb0614e
commit
10943d9c6d
@ -41,7 +41,8 @@ class Configuration implements ConfigurationInterface
|
||||
->min(-1)
|
||||
->defaultValue(-1)
|
||||
->end()
|
||||
->end();
|
||||
->end()
|
||||
;
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
<div class="sf-toolbar-info-piece">
|
||||
in
|
||||
{% if dump.file %}
|
||||
{% set link = dump.file|file_link(dump.line) }} %}
|
||||
{% set link = dump.file|file_link(dump.line) %}
|
||||
{% if link %}
|
||||
<a href="{{ link }}" title="{{ dump.file }}">{{ dump.name }}</a>
|
||||
{% else %}
|
||||
@ -76,7 +76,7 @@
|
||||
<li class="sf-dump sf-reset">
|
||||
in
|
||||
{% if dump.line %}
|
||||
{% set link = dump.file|file_link(dump.line) }} %}
|
||||
{% set link = dump.file|file_link(dump.line) %}
|
||||
{% if link %}
|
||||
<a href="{{ link }}" title="{{ dump.file }}">{{ dump.name }}</a>
|
||||
{% else %}
|
||||
|
@ -15,7 +15,6 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
use Symfony\Component\VarDumper\Cloner\Data;
|
||||
use Symfony\Component\VarDumper\Dumper\JsonDumper;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
|
||||
@ -158,8 +157,6 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface
|
||||
{
|
||||
if ('html' === $format) {
|
||||
$dumper = new HtmlDumper();
|
||||
} elseif ('json' === $format) {
|
||||
$dumper = new JsonDumper();
|
||||
} else {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid dump format: %s', $format));
|
||||
}
|
||||
|
@ -22,11 +22,13 @@ class CasterStub extends Stub
|
||||
{
|
||||
public function __construct($value, $class = '')
|
||||
{
|
||||
$this->class = $class;
|
||||
$this->value = $value;
|
||||
|
||||
switch (gettype($value)) {
|
||||
case 'object':
|
||||
$this->type = self::TYPE_OBJECT;
|
||||
$this->class = get_class($value);
|
||||
$this->value = spl_object_hash($value);
|
||||
$this->cut = -1;
|
||||
break;
|
||||
|
||||
@ -40,7 +42,6 @@ class CasterStub extends Stub
|
||||
case 'unknown type':
|
||||
$this->type = self::TYPE_RESOURCE;
|
||||
$this->class = @get_resource_type($value);
|
||||
$this->value = (int) $value;
|
||||
$this->cut = -1;
|
||||
break;
|
||||
|
||||
@ -49,13 +50,8 @@ class CasterStub extends Stub
|
||||
$this->type = self::TYPE_STRING;
|
||||
$this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
|
||||
$this->cut = self::STRING_BINARY === $this->class ? strlen($value) : (function_exists('iconv_strlen') ? iconv_strlen($value, 'UTF-8') : -1);
|
||||
break;
|
||||
$this->value = '';
|
||||
}
|
||||
// No break;
|
||||
|
||||
default:
|
||||
$this->class = $class;
|
||||
$this->value = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -174,14 +174,14 @@ abstract class AbstractCloner implements ClonerInterface
|
||||
/**
|
||||
* Casts an object to an array representation.
|
||||
*
|
||||
* @param object $obj The object itself.
|
||||
* @param Stub $stub The Stub for the casted object.
|
||||
* @param bool $isNested True if the object is nested in the dumped structure.
|
||||
*
|
||||
* @return array The object casted as array.
|
||||
*/
|
||||
protected function castObject($obj, Stub $stub, $isNested)
|
||||
protected function castObject(Stub $stub, $isNested)
|
||||
{
|
||||
$obj = $stub->value;
|
||||
$class = $stub->class;
|
||||
|
||||
if (isset($this->classInfo[$class])) {
|
||||
@ -225,15 +225,15 @@ abstract class AbstractCloner implements ClonerInterface
|
||||
/**
|
||||
* Casts a resource to an array representation.
|
||||
*
|
||||
* @param resource $res The resource.
|
||||
* @param Stub $stub The Stub for the casted resource.
|
||||
* @param bool $isNested True if the object is nested in the dumped structure.
|
||||
*
|
||||
* @return array The resource casted as array.
|
||||
*/
|
||||
protected function castResource($res, Stub $stub, $isNested)
|
||||
protected function castResource(Stub $stub, $isNested)
|
||||
{
|
||||
$a = array();
|
||||
$res = $stub->value;
|
||||
$type = $stub->class;
|
||||
|
||||
if (!empty($this->casters[':'.$type])) {
|
||||
|
@ -200,8 +200,8 @@ class Data
|
||||
*/
|
||||
public static function utf8Encode($s)
|
||||
{
|
||||
if (function_exists('iconv')) {
|
||||
return iconv('CP1252', 'UTF-8', $s);
|
||||
if (function_exists('mb_convert_encoding')) {
|
||||
return mb_convert_encoding($s, 'UTF-8', 'CP1252');
|
||||
}
|
||||
|
||||
$s .= $s;
|
||||
|
@ -95,16 +95,18 @@ class ExtCloner extends AbstractCloner
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_OBJECT;
|
||||
$stub->class = $zval['object_class'];
|
||||
$stub->value = $h;
|
||||
$a = $this->castObject($v, $stub, 0 < $i);
|
||||
if (Stub::TYPE_OBJECT !== $stub->type) {
|
||||
break;
|
||||
$stub->value = $v;
|
||||
$a = $this->castObject($stub, 0 < $i);
|
||||
if ($v !== $stub->value) {
|
||||
if (Stub::TYPE_OBJECT !== $stub->type) {
|
||||
break;
|
||||
}
|
||||
$h = spl_object_hash($stub->value);
|
||||
}
|
||||
$h = $stub->value;
|
||||
$stub->value = '';
|
||||
$stub->value = null;
|
||||
if (0 <= $maxItems && $maxItems <= $pos) {
|
||||
$stub->cut = count($a);
|
||||
$a = array();
|
||||
$a = null;
|
||||
}
|
||||
}
|
||||
if (empty($softRefs[$h])) {
|
||||
@ -112,6 +114,7 @@ class ExtCloner extends AbstractCloner
|
||||
} else {
|
||||
$stub = $softRefs[$h];
|
||||
$stub->ref = ++$refs;
|
||||
$a = null;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -120,16 +123,18 @@ class ExtCloner extends AbstractCloner
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_RESOURCE;
|
||||
$stub->class = $zval['resource_type'];
|
||||
$stub->value = $h;
|
||||
$a = $this->castResource($v, $stub, 0 < $i);
|
||||
if (Stub::TYPE_RESOURCE !== $stub->type) {
|
||||
break;
|
||||
$stub->value = $v;
|
||||
$a = $this->castResource($stub, 0 < $i);
|
||||
if ($v !== $stub->value) {
|
||||
if (Stub::TYPE_RESOURCE !== $stub->type) {
|
||||
break;
|
||||
}
|
||||
$h = (int) $stub->value;
|
||||
}
|
||||
$h = $stub->value;
|
||||
$stub->value = '';
|
||||
$stub->value = null;
|
||||
if (0 <= $maxItems && $maxItems <= $pos) {
|
||||
$stub->cut = count($a);
|
||||
$a = array();
|
||||
$a = null;
|
||||
}
|
||||
}
|
||||
if (empty($softRefs[$h])) {
|
||||
@ -137,6 +142,7 @@ class ExtCloner extends AbstractCloner
|
||||
} else {
|
||||
$stub = $softRefs[$h];
|
||||
$stub->ref = ++$refs;
|
||||
$a = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -101,16 +101,18 @@ class PhpCloner extends AbstractCloner
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_OBJECT;
|
||||
$stub->class = get_class($v);
|
||||
$stub->value = $h;
|
||||
$a = $this->castObject($v, $stub, 0 < $i);
|
||||
if (Stub::TYPE_OBJECT !== $stub->type) {
|
||||
break;
|
||||
$stub->value = $v;
|
||||
$a = $this->castObject($stub, 0 < $i);
|
||||
if ($v !== $stub->value) {
|
||||
if (Stub::TYPE_OBJECT !== $stub->type) {
|
||||
break;
|
||||
}
|
||||
$h = spl_object_hash($stub->value);
|
||||
}
|
||||
$h = $stub->value;
|
||||
$stub->value = '';
|
||||
$stub->value = null;
|
||||
if (0 <= $maxItems && $maxItems <= $pos) {
|
||||
$stub->cut = count($a);
|
||||
$a = array();
|
||||
$a = null;
|
||||
}
|
||||
}
|
||||
if (empty($softRefs[$h])) {
|
||||
@ -118,6 +120,7 @@ class PhpCloner extends AbstractCloner
|
||||
} else {
|
||||
$stub = $softRefs[$h];
|
||||
$stub->ref = ++$refs;
|
||||
$a = null;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -127,16 +130,18 @@ class PhpCloner extends AbstractCloner
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_RESOURCE;
|
||||
$stub->class = get_resource_type($v);
|
||||
$stub->value = $h;
|
||||
$a = $this->castResource($v, $stub, 0 < $i);
|
||||
if (Stub::TYPE_RESOURCE !== $stub->type) {
|
||||
break;
|
||||
$stub->value = $v;
|
||||
$a = $this->castResource($stub, 0 < $i);
|
||||
if ($v !== $stub->value) {
|
||||
if (Stub::TYPE_RESOURCE !== $stub->type) {
|
||||
break;
|
||||
}
|
||||
$h = (int) $stub->value;
|
||||
}
|
||||
$h = $stub->value;
|
||||
$stub->value = '';
|
||||
$stub->value = null;
|
||||
if (0 <= $maxItems && $maxItems <= $pos) {
|
||||
$stub->cut = count($a);
|
||||
$a = array();
|
||||
$a = null;
|
||||
}
|
||||
}
|
||||
if (empty($softRefs[$h])) {
|
||||
@ -144,6 +149,7 @@ class PhpCloner extends AbstractCloner
|
||||
} else {
|
||||
$stub = $softRefs[$h];
|
||||
$stub->ref = ++$refs;
|
||||
$a = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ class CliDumperTest extends \PHPUnit_Framework_TestCase
|
||||
$out = ob_get_clean();
|
||||
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
|
||||
$out = preg_replace('/[ \t]+$/m', '', $out);
|
||||
$intMax = PHP_INT_MAX;
|
||||
|
||||
$this->assertSame(
|
||||
<<<EOTXT
|
||||
@ -52,7 +53,7 @@ array:25 [
|
||||
3 => NAN
|
||||
4 => INF
|
||||
5 => -INF
|
||||
6 => 9223372036854775807
|
||||
6 => {$intMax}
|
||||
"str" => "déjà"
|
||||
7 => b"é"
|
||||
"[]" => []
|
||||
|
@ -43,6 +43,7 @@ class HtmlDumperTest extends \PHPUnit_Framework_TestCase
|
||||
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
|
||||
$out = preg_replace('/[ \t]+$/m', '', $out);
|
||||
$var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8');
|
||||
$intMax = PHP_INT_MAX;
|
||||
|
||||
$this->assertSame(
|
||||
<<<EOTXT
|
||||
@ -55,7 +56,7 @@ class HtmlDumperTest extends \PHPUnit_Framework_TestCase
|
||||
<span class=sf-dump-meta>3</span> => <span class=sf-dump-num>NAN</span>
|
||||
<span class=sf-dump-meta>4</span> => <span class=sf-dump-num>INF</span>
|
||||
<span class=sf-dump-meta>5</span> => <span class=sf-dump-num>-INF</span>
|
||||
<span class=sf-dump-meta>6</span> => <span class=sf-dump-num>9223372036854775807</span>
|
||||
<span class=sf-dump-meta>6</span> => <span class=sf-dump-num>{$intMax}</span>
|
||||
"<span class=sf-dump-meta>str</span>" => "<span class=sf-dump-str>déjà</span>"
|
||||
<span class=sf-dump-meta>7</span> => b"<span class=sf-dump-str>é</span>"
|
||||
"<span class=sf-dump-meta>[]</span>" => []
|
||||
|
Reference in New Issue
Block a user