[VarDumper] Sfdump JS ns and VarCloner replacing Ext+PhpCloner
This commit is contained in:
parent
966c586ff1
commit
da96ad846d
@ -13,7 +13,7 @@ namespace Symfony\Bridge\Twig\Tests\Extension;
|
||||
|
||||
use Symfony\Bridge\Twig\Extension\DumpExtension;
|
||||
use Symfony\Component\VarDumper\VarDumper;
|
||||
use Symfony\Component\VarDumper\Cloner\PhpCloner;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
|
||||
class DumpExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@ -22,7 +22,7 @@ class DumpExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testDumpTag($template, $debug, $expectedOutput, $expectedDumped)
|
||||
{
|
||||
$extension = new DumpExtension(new PhpCloner());
|
||||
$extension = new DumpExtension(new VarCloner());
|
||||
$twig = new \Twig_Environment(new \Twig_Loader_String(), array(
|
||||
'debug' => $debug,
|
||||
'cache' => false,
|
||||
@ -62,7 +62,7 @@ class DumpExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testDump($context, $args, $expectedOutput, $debug = true)
|
||||
{
|
||||
$extension = new DumpExtension(new PhpCloner());
|
||||
$extension = new DumpExtension(new VarCloner());
|
||||
$twig = new \Twig_Environment(new \Twig_Loader_String(), array(
|
||||
'debug' => $debug,
|
||||
'cache' => false,
|
||||
@ -77,7 +77,7 @@ class DumpExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
if ($debug) {
|
||||
$this->assertStringStartsWith('<script>', $dump);
|
||||
$dump = preg_replace('/^.*?<pre/', '<pre', $dump);
|
||||
$dump = preg_replace('/sf-dump-\\d{2,}/', 'sf-dump', $dump);
|
||||
$dump = preg_replace('/sf-dump-\d+/', 'sf-dump', $dump);
|
||||
}
|
||||
$this->assertEquals($expectedOutput, $dump);
|
||||
}
|
||||
@ -86,12 +86,12 @@ class DumpExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
return array(
|
||||
array(array(), array(), '', false),
|
||||
array(array(), array(), "<pre class=sf-dump>[]\n</pre><script>Sfjs.dump.instrument()</script>\n"),
|
||||
array(array(), array(), "<pre class=sf-dump>[]\n</pre><script>Sfdump.instrument()</script>\n"),
|
||||
array(
|
||||
array(),
|
||||
array(123, 456),
|
||||
"<pre class=sf-dump><span class=sf-dump-num>123</span>\n</pre><script>Sfjs.dump.instrument()</script>\n"
|
||||
."<pre class=sf-dump><span class=sf-dump-num>456</span>\n</pre><script>Sfjs.dump.instrument()</script>\n",
|
||||
"<pre class=sf-dump><span class=sf-dump-num>123</span>\n</pre><script>Sfdump.instrument()</script>\n"
|
||||
."<pre class=sf-dump><span class=sf-dump-num>456</span>\n</pre><script>Sfdump.instrument()</script>\n",
|
||||
),
|
||||
array(
|
||||
array('foo' => 'bar'),
|
||||
@ -99,7 +99,7 @@ class DumpExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
"<pre class=sf-dump><span class=sf-dump-note>array:1</span> [<span name=sf-dump-child>\n"
|
||||
." \"<span class=sf-dump-meta>foo</span>\" => \"<span class=sf-dump-str>bar</span>\"\n"
|
||||
."</span>]\n"
|
||||
."</pre><script>Sfjs.dump.instrument()</script>\n",
|
||||
."</pre><script>Sfdump.instrument()</script>\n",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -34,11 +34,6 @@ class DebugExtension extends Extension
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('services.xml');
|
||||
|
||||
$container->setParameter(
|
||||
'var_dumper.cloner.class',
|
||||
'Symfony\Component\VarDumper\Cloner\\'.(function_exists('symfony_zval_info') ? 'Ext' : 'Php').'Cloner'
|
||||
);
|
||||
|
||||
$container->getDefinition('var_dumper.cloner')
|
||||
->addMethodCall('setMaxItems', array($config['max_items']))
|
||||
->addMethodCall('setMaxString', array($config['max_string_length']));
|
||||
|
@ -4,25 +4,20 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="data_collector.dump.class">Symfony\Component\HttpKernel\DataCollector\DumpDataCollector</parameter>
|
||||
<parameter key="debug.dump_listener.class">Symfony\Component\HttpKernel\EventListener\DumpListener</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="data_collector.dump" class="%data_collector.dump.class%">
|
||||
<service id="data_collector.dump" class="Symfony\Component\HttpKernel\DataCollector\DumpDataCollector">
|
||||
<tag name="data_collector" id="dump" template="@Debug/Profiler/dump.html.twig" />
|
||||
<argument type="service" id="debug.stopwatch" on-invalid="ignore" />
|
||||
<argument>%templating.helper.code.file_link_format%</argument>
|
||||
</service>
|
||||
|
||||
<service id="debug.dump_listener" class="%debug.dump_listener.class%">
|
||||
<service id="debug.dump_listener" class="Symfony\Component\HttpKernel\EventListener\DumpListener">
|
||||
<tag name="kernel.event_subscriber" />
|
||||
<argument type="service" id="service_container" />
|
||||
<argument>data_collector.dump</argument>
|
||||
</service>
|
||||
|
||||
<service id="var_dumper.cloner" class="%var_dumper.cloner.class%" />
|
||||
<service id="var_dumper.cloner" class="Symfony\Component\VarDumper\Cloner\VarCloner" />
|
||||
</services>
|
||||
|
||||
</container>
|
||||
|
@ -84,7 +84,7 @@
|
||||
{{ dump.name }}
|
||||
{% endif %}
|
||||
line {{ dump.line }}:
|
||||
<a onclick="Sfjs.dump.toggle(this)">▶</a>
|
||||
<a onclick="Sfdump.toggle(this)">▶</a>
|
||||
<span class="sf-dump-compact">
|
||||
{% if dump.fileExcerpt %}{{ dump.fileExcerpt|raw }}{% else %}{{ dump.file|file_excerpt(dump.line) }}{% endif %}
|
||||
</span>
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
<parameters>
|
||||
<parameter key="debug.templating.engine.twig.class">Symfony\Bundle\TwigBundle\Debug\TimedTwigEngine</parameter>
|
||||
<parameter key="twig.extension.dump.class">Symfony\Bridge\Twig\Extension\DumpExtension</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
@ -17,7 +16,7 @@
|
||||
<argument type="service" id="debug.stopwatch" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.dump" class="%twig.extension.dump.class%" public="false">
|
||||
<service id="twig.extension.dump" class="Symfony\Bridge\Twig\Extension\DumpExtension" public="false">
|
||||
<tag name="twig.extension" />
|
||||
<argument type="service" id="var_dumper.cloner" on-invalid="null" />
|
||||
</service>
|
||||
|
@ -38,7 +38,7 @@ class DumpDataCollectorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$xDump = array(
|
||||
array(
|
||||
'data' => "<pre class=sf-dump><span class=sf-dump-num>123</span>\n</pre><script>Sfjs.dump.instrument()</script>\n",
|
||||
'data' => "<pre class=sf-dump><span class=sf-dump-num>123</span>\n</pre><script>Sfdump.instrument()</script>\n",
|
||||
'name' => 'DumpDataCollectorTest.php',
|
||||
'file' => __FILE__,
|
||||
'line' => $line,
|
||||
|
@ -1,201 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\VarDumper\Cloner;
|
||||
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class ExtCloner extends AbstractCloner
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doClone($var)
|
||||
{
|
||||
$i = 0; // Current iteration position in $queue
|
||||
$len = 1; // Length of $queue
|
||||
$pos = 0; // Number of cloned items past the first level
|
||||
$refs = 0; // Number of hard+soft references in $var
|
||||
$queue = array(array($var)); // This breadth-first queue is the return value
|
||||
$arrayRefs = array(); // Map of queue indexes to stub array objects
|
||||
$hardRefs = array(); // Map of original zval hashes to stub objects
|
||||
$softRefs = array(); // Map of original object hashes to their stub object couterpart
|
||||
$maxItems = $this->maxItems;
|
||||
$maxString = $this->maxString;
|
||||
$a = null; // Array cast for nested structures
|
||||
$stub = null; // Stub capturing the main properties of an original item value,
|
||||
// or null if the original value is used directly
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$indexed = true; // Whether the currently iterated array is numerically indexed or not
|
||||
$j = -1; // Position in the currently iterated array
|
||||
$step = $queue[$i]; // Copy of the currently iterated array used for hard references detection
|
||||
foreach ($step as $k => $v) {
|
||||
// $k is the original key
|
||||
// $v is the original value or a stub object in case of hard references
|
||||
if ($indexed && $k !== ++$j) {
|
||||
$indexed = false;
|
||||
}
|
||||
$zval = symfony_zval_info($k, $step);
|
||||
if ($zval['zval_isref']) {
|
||||
$queue[$i][$k] =& $stub; // Break hard references to make $queue completely
|
||||
unset($stub); // independent from the original structure
|
||||
if (isset($hardRefs[$h = $zval['zval_hash']])) {
|
||||
$hardRefs[$h]->ref = ++$refs;
|
||||
$queue[$i][$k] = $hardRefs[$h];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Create $stub when the original value $v can not be used directly
|
||||
// If $v is a nested structure, put that structure in array $a
|
||||
switch ($zval['type']) {
|
||||
case 'string':
|
||||
if (isset($v[0]) && !preg_match('//u', $v)) {
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_STRING;
|
||||
$stub->class = Stub::STRING_BINARY;
|
||||
if (0 <= $maxString && 0 < $cut = strlen($v) - $maxString) {
|
||||
$stub->cut = $cut;
|
||||
$v = substr_replace($v, '', -$cut);
|
||||
}
|
||||
$stub->value = Data::utf8Encode($v);
|
||||
} elseif (0 <= $maxString && isset($v[1+($maxString>>2)]) && 0 < $cut = iconv_strlen($v, 'UTF-8') - $maxString) {
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_STRING;
|
||||
$stub->class = Stub::STRING_UTF8;
|
||||
$stub->cut = $cut;
|
||||
$stub->value = iconv_substr($v, 0, $maxString, 'UTF-8');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'integer':
|
||||
break;
|
||||
|
||||
case 'array':
|
||||
if ($v) {
|
||||
$stub = $arrayRefs[$len] = new Stub();
|
||||
$stub->type = Stub::TYPE_ARRAY;
|
||||
$stub->class = Stub::ARRAY_ASSOC;
|
||||
$stub->value = $zval['array_count'];
|
||||
$a = $v;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'object':
|
||||
if (empty($softRefs[$h = $zval['object_hash']])) {
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_OBJECT;
|
||||
$stub->class = $zval['object_class'];
|
||||
$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);
|
||||
}
|
||||
$stub->value = null;
|
||||
if (0 <= $maxItems && $maxItems <= $pos) {
|
||||
$stub->cut = count($a);
|
||||
$a = null;
|
||||
}
|
||||
}
|
||||
if (empty($softRefs[$h])) {
|
||||
$softRefs[$h] = $stub;
|
||||
} else {
|
||||
$stub = $softRefs[$h];
|
||||
$stub->ref = ++$refs;
|
||||
$a = null;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'resource':
|
||||
if (empty($softRefs[$h = (int) $v])) {
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_RESOURCE;
|
||||
$stub->class = $zval['resource_type'];
|
||||
$stub->value = $v;
|
||||
$a = $this->castResource($stub, 0 < $i);
|
||||
if ($v !== $stub->value) {
|
||||
if (Stub::TYPE_RESOURCE !== $stub->type) {
|
||||
break;
|
||||
}
|
||||
$h = (int) $stub->value;
|
||||
}
|
||||
$stub->value = null;
|
||||
if (0 <= $maxItems && $maxItems <= $pos) {
|
||||
$stub->cut = count($a);
|
||||
$a = null;
|
||||
}
|
||||
}
|
||||
if (empty($softRefs[$h])) {
|
||||
$softRefs[$h] = $stub;
|
||||
} else {
|
||||
$stub = $softRefs[$h];
|
||||
$stub->ref = ++$refs;
|
||||
$a = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($stub)) {
|
||||
if ($zval['zval_isref']) {
|
||||
if (Stub::TYPE_ARRAY === $stub->type) {
|
||||
$queue[$i][$k] = $hardRefs[$zval['zval_hash']] = $stub;
|
||||
} else {
|
||||
$queue[$i][$k] = $hardRefs[$zval['zval_hash']] = $v = new Stub();
|
||||
$v->value = $stub;
|
||||
}
|
||||
} else {
|
||||
$queue[$i][$k] = $stub;
|
||||
}
|
||||
|
||||
if ($a) {
|
||||
if ($i && 0 <= $maxItems) {
|
||||
$k = count($a);
|
||||
if ($pos < $maxItems) {
|
||||
if ($maxItems < $pos += $k) {
|
||||
$a = array_slice($a, 0, $maxItems - $pos);
|
||||
if ($stub->cut >= 0) {
|
||||
$stub->cut += $pos - $maxItems;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($stub->cut >= 0) {
|
||||
$stub->cut += $k;
|
||||
}
|
||||
$stub = $a = null;
|
||||
unset($arrayRefs[$len]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$queue[$len] = $a;
|
||||
$stub->position = $len++;
|
||||
}
|
||||
$stub = $a = null;
|
||||
} elseif ($zval['zval_isref']) {
|
||||
$queue[$i][$k] = $hardRefs[$zval['zval_hash']] = new Stub();
|
||||
$queue[$i][$k]->value = $v;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arrayRefs[$i])) {
|
||||
if ($indexed) {
|
||||
$arrayRefs[$i]->class = Stub::ARRAY_INDEXED;
|
||||
}
|
||||
unset($arrayRefs[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $queue;
|
||||
}
|
||||
}
|
@ -14,29 +14,37 @@ namespace Symfony\Component\VarDumper\Cloner;
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class PhpCloner extends AbstractCloner
|
||||
class VarCloner extends AbstractCloner
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function doClone($var)
|
||||
{
|
||||
$useExt = extension_loaded('symfony_debug');
|
||||
$i = 0; // Current iteration position in $queue
|
||||
$len = 1; // Length of $queue
|
||||
$pos = 0; // Number of cloned items past the first level
|
||||
$refs = 0; // Number of hard+soft references in $var
|
||||
$queue = array(array($var)); // This breadth-first queue is the return value
|
||||
$arrayRefs = array(); // Map of queue indexes to stub array objects
|
||||
$hardRefs = array(); // By-ref map of stub objects' hashes to original hard `&` references
|
||||
$hardRefs = array(); // Map of original zval hashes to stub objects
|
||||
$softRefs = array(); // Map of original object hashes to their stub object couterpart
|
||||
$values = array(); // Map of stub objects' hashes to original values
|
||||
$maxItems = $this->maxItems;
|
||||
$maxString = $this->maxString;
|
||||
$cookie = (object) array(); // Unique object used to detect hard references
|
||||
$isRef = false;
|
||||
$a = null; // Array cast for nested structures
|
||||
$stub = null; // Stub capturing the main properties of an original item value,
|
||||
// or null if the original value is used directly
|
||||
$zval = array( // Main properties of the current value
|
||||
'type' => null,
|
||||
'zval_isref' => null,
|
||||
'array_count' => null,
|
||||
'object_class' => null,
|
||||
'object_hash' => null,
|
||||
'resource_type' => null,
|
||||
);
|
||||
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$indexed = true; // Whether the currently iterated array is numerically indexed or not
|
||||
@ -48,8 +56,20 @@ class PhpCloner extends AbstractCloner
|
||||
if ($indexed && $k !== ++$j) {
|
||||
$indexed = false;
|
||||
}
|
||||
if ($useExt) {
|
||||
$zval = symfony_zval_info($k, $step);
|
||||
if ($zval['zval_isref']) {
|
||||
$queue[$i][$k] =& $stub; // Break hard references to make $queue completely
|
||||
unset($stub); // independent from the original structure
|
||||
if (isset($hardRefs[$h = $zval['zval_hash']])) {
|
||||
$hardRefs[$h]->ref = ++$refs;
|
||||
$queue[$i][$k] = $hardRefs[$h];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$step[$k] = $cookie;
|
||||
if ($queue[$i][$k] === $cookie) {
|
||||
if ($zval['zval_isref'] = $queue[$i][$k] === $cookie) {
|
||||
$queue[$i][$k] =& $stub; // Break hard references to make $queue completely
|
||||
unset($stub); // independent from the original structure
|
||||
if ($v instanceof Stub && isset($hardRefs[spl_object_hash($v)])) {
|
||||
@ -57,11 +77,12 @@ class PhpCloner extends AbstractCloner
|
||||
$step[$k] = $queue[$i][$k] = $v;
|
||||
continue;
|
||||
}
|
||||
$isRef = true;
|
||||
}
|
||||
$zval['type'] = gettype($v);
|
||||
}
|
||||
// Create $stub when the original value $v can not be used directly
|
||||
// If $v is a nested structure, put that structure in array $a
|
||||
switch (gettype($v)) {
|
||||
switch ($zval['type']) {
|
||||
case 'string':
|
||||
if (isset($v[0]) && !preg_match('//u', $v)) {
|
||||
$stub = new Stub();
|
||||
@ -74,7 +95,7 @@ class PhpCloner extends AbstractCloner
|
||||
$cut = $v;
|
||||
}
|
||||
$stub->value = Data::utf8Encode($cut);
|
||||
} elseif (0 <= $maxString && isset($v[1+($maxString>>2)]) && 0 < $cut = iconv_strlen($v, 'UTF-8') - $maxString) {
|
||||
} elseif (0 <= $maxString && isset($v[1 + ($maxString >> 2)]) && 0 < $cut = iconv_strlen($v, 'UTF-8') - $maxString) {
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_STRING;
|
||||
$stub->class = Stub::STRING_UTF8;
|
||||
@ -91,16 +112,16 @@ class PhpCloner extends AbstractCloner
|
||||
$stub = $arrayRefs[$len] = new Stub();
|
||||
$stub->type = Stub::TYPE_ARRAY;
|
||||
$stub->class = Stub::ARRAY_ASSOC;
|
||||
$stub->value = count($v);
|
||||
$stub->value = $v ? $zval['array_count'] ?: count($v) : 0;
|
||||
$a = $v;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'object':
|
||||
if (empty($softRefs[$h = spl_object_hash($v)])) {
|
||||
if (empty($softRefs[$h = $zval['object_hash'] ?: spl_object_hash($v)])) {
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_OBJECT;
|
||||
$stub->class = get_class($v);
|
||||
$stub->class = $zval['object_class'] ?: get_class($v);
|
||||
$stub->value = $v;
|
||||
$a = $this->castObject($stub, 0 < $i);
|
||||
if ($v !== $stub->value) {
|
||||
@ -129,7 +150,7 @@ class PhpCloner extends AbstractCloner
|
||||
if (empty($softRefs[$h = (int) $v])) {
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_RESOURCE;
|
||||
$stub->class = get_resource_type($v);
|
||||
$stub->class = $zval['resource_type'] ?: get_resource_type($v);
|
||||
$stub->value = $v;
|
||||
$a = $this->castResource($stub, 0 < $i);
|
||||
if ($v !== $stub->value) {
|
||||
@ -155,7 +176,15 @@ class PhpCloner extends AbstractCloner
|
||||
}
|
||||
|
||||
if (isset($stub)) {
|
||||
if ($isRef) {
|
||||
if ($zval['zval_isref']) {
|
||||
if ($useExt) {
|
||||
if (Stub::TYPE_ARRAY === $stub->type) {
|
||||
$queue[$i][$k] = $hardRefs[$zval['zval_hash']] = $stub;
|
||||
} else {
|
||||
$queue[$i][$k] = $hardRefs[$zval['zval_hash']] = $v = new Stub();
|
||||
$v->value = $stub;
|
||||
}
|
||||
} else {
|
||||
if (Stub::TYPE_ARRAY === $stub->type) {
|
||||
$step[$k] = $stub;
|
||||
} else {
|
||||
@ -165,7 +194,7 @@ class PhpCloner extends AbstractCloner
|
||||
$h = spl_object_hash($step[$k]);
|
||||
$queue[$i][$k] = $hardRefs[$h] =& $step[$k];
|
||||
$values[$h] = $v;
|
||||
$isRef = false;
|
||||
}
|
||||
} else {
|
||||
$queue[$i][$k] = $stub;
|
||||
}
|
||||
@ -193,13 +222,17 @@ class PhpCloner extends AbstractCloner
|
||||
$stub->position = $len++;
|
||||
}
|
||||
$stub = $a = null;
|
||||
} elseif ($isRef) {
|
||||
} elseif ($zval['zval_isref']) {
|
||||
if ($useExt) {
|
||||
$queue[$i][$k] = $hardRefs[$zval['zval_hash']] = new Stub();
|
||||
$queue[$i][$k]->value = $v;
|
||||
} else {
|
||||
$step[$k] = $queue[$i][$k] = new Stub();
|
||||
$step[$k]->value = $v;
|
||||
$h = spl_object_hash($step[$k]);
|
||||
$hardRefs[$h] =& $step[$k];
|
||||
$values[$h] = $v;
|
||||
$isRef = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class HtmlDumper extends CliDumper
|
||||
|
||||
protected $dumpHeader;
|
||||
protected $dumpPrefix = '<pre class=sf-dump>';
|
||||
protected $dumpSuffix = '</pre><script>Sfjs.dump.instrument()</script>';
|
||||
protected $dumpSuffix = '</pre><script>Sfdump.instrument()</script>';
|
||||
protected $dumpId = 'sf-dump';
|
||||
protected $colors = true;
|
||||
protected $headerIsDumped = false;
|
||||
@ -106,17 +106,16 @@ class HtmlDumper extends CliDumper
|
||||
|
||||
$line = <<<'EOHTML'
|
||||
<script>
|
||||
Sfjs = window.Sfjs || {};
|
||||
Sfjs.dump = Sfjs.dump || {};
|
||||
Sfjs.dump.childElts = Sfjs.dump.childElts || document.getElementsByName('sf-dump-child');
|
||||
Sfjs.dump.childLen = Sfjs.dump.childLen || 0;
|
||||
Sfjs.dump.refElts = Sfjs.dump.refElts || document.getElementsByName('sf-dump-ref');
|
||||
Sfjs.dump.refLen = Sfjs.dump.refLen || 0;
|
||||
if (!Sfjs.dump.refStyle) {
|
||||
Sfjs.dump.refStyle = document.createElement('style');
|
||||
document.documentElement.firstChild.appendChild(Sfjs.dump.refStyle);
|
||||
Sfdump = window.Sfdump || {};
|
||||
Sfdump.childElts = Sfdump.childElts || document.getElementsByName('sf-dump-child');
|
||||
Sfdump.childLen = Sfdump.childLen || 0;
|
||||
Sfdump.refElts = Sfdump.refElts || document.getElementsByName('sf-dump-ref');
|
||||
Sfdump.refLen = Sfdump.refLen || 0;
|
||||
if (!Sfdump.refStyle) {
|
||||
Sfdump.refStyle = document.createElement('style');
|
||||
document.documentElement.firstChild.appendChild(Sfdump.refStyle);
|
||||
}
|
||||
Sfjs.dump.instrument = Sfjs.dump.instrument || function () {
|
||||
Sfdump.instrument = Sfdump.instrument || function () {
|
||||
var elt, i, ref;
|
||||
|
||||
i = this.childLen;
|
||||
@ -126,13 +125,13 @@ Sfjs.dump.instrument = Sfjs.dump.instrument || function () {
|
||||
elt = this.childElts[i];
|
||||
if ("" == elt.className) {
|
||||
elt.className = "sf-dump-child";
|
||||
elt.innerHTML = '<a class=sf-dump-ref onclick="Sfjs.dump.toggle(this)"><span>▼</span></a><span class="sf-dump-expanded">'+elt.innerHTML+'</span>';
|
||||
elt.innerHTML = '<a class=sf-dump-ref onclick="Sfdump.toggle(this)"><span>▼</span></a><span class="sf-dump-expanded">'+elt.innerHTML+'</span>';
|
||||
if ('sf-dump-expanded' == elt.parentNode.className) {
|
||||
if (elt.children[1].firstChild.nextSibling.id) {
|
||||
elt.firstChild.appendChild(elt.children[1].firstChild);
|
||||
elt.firstChild.appendChild(elt.children[1].firstChild);
|
||||
}
|
||||
Sfjs.dump.toggle(elt.firstChild);
|
||||
Sfdump.toggle(elt.firstChild);
|
||||
}
|
||||
}
|
||||
++i;
|
||||
@ -157,11 +156,11 @@ Sfjs.dump.instrument = Sfjs.dump.instrument || function () {
|
||||
try {
|
||||
t.replaceChild(r, elt);
|
||||
f.replaceChild(elt, c);
|
||||
Sfjs.dump.refStyle.innerHTML = '';
|
||||
Sfdump.refStyle.innerHTML = '';
|
||||
r = r.firstChild;
|
||||
c = r.nextSibling;
|
||||
if ('sf-dump-compact' == c.className) {
|
||||
Sfjs.dump.toggle(r);
|
||||
Sfdump.toggle(r);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -174,10 +173,10 @@ Sfjs.dump.instrument = Sfjs.dump.instrument || function () {
|
||||
}
|
||||
elt.className += ' '+ref;
|
||||
elt.onmouseover = function() {
|
||||
Sfjs.dump.refStyle.innerHTML = 'pre.sf-dump .'+ref+'{background-color: yellow; border-radius: 2px}';
|
||||
Sfdump.refStyle.innerHTML = 'pre.sf-dump .'+ref+'{background-color: yellow; border-radius: 2px}';
|
||||
};
|
||||
elt.onmouseout = function() {
|
||||
Sfjs.dump.refStyle.innerHTML = '';
|
||||
Sfdump.refStyle.innerHTML = '';
|
||||
};
|
||||
}
|
||||
|
||||
@ -189,7 +188,7 @@ Sfjs.dump.instrument = Sfjs.dump.instrument || function () {
|
||||
++i;
|
||||
}
|
||||
};
|
||||
Sfjs.dump.toggle = Sfjs.dump.toggle || function(a) {
|
||||
Sfdump.toggle = Sfdump.toggle || function(a) {
|
||||
var s = a.nextElementSibling;
|
||||
|
||||
if ('sf-dump-compact' == s.className) {
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\VarDumper\Tests;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\PhpCloner;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
|
||||
/**
|
||||
@ -25,13 +25,13 @@ class CliDumperTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$dumper = new CliDumper('php://output');
|
||||
$dumper->setColors(false);
|
||||
$cloner = new PhpCloner();
|
||||
$cloner = new VarCloner();
|
||||
$cloner->addCasters(array(
|
||||
':stream' => function ($res, $a) {
|
||||
unset($a['uri']);
|
||||
|
||||
return $a;
|
||||
}
|
||||
},
|
||||
));
|
||||
$data = $cloner->cloneVar($var);
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\VarDumper\Tests;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\PhpCloner;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||
|
||||
/**
|
||||
@ -27,7 +27,7 @@ class HtmlDumperTest extends \PHPUnit_Framework_TestCase
|
||||
$dumper->setColors(false);
|
||||
$dumper->setDumpHeader('<foo></foo>');
|
||||
$dumper->setDumpBoundaries('<bar>', '</bar>');
|
||||
$cloner = new PhpCloner();
|
||||
$cloner = new VarCloner();
|
||||
$cloner->addCasters(array(
|
||||
':stream' => function ($res, $a) {
|
||||
unset($a['uri']);
|
||||
|
@ -11,8 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\VarDumper;
|
||||
|
||||
use Symfony\Component\VarDumper\Cloner\ExtCloner;
|
||||
use Symfony\Component\VarDumper\Cloner\PhpCloner;
|
||||
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
||||
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
||||
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
|
||||
|
||||
@ -26,7 +25,7 @@ class VarDumper
|
||||
public static function dump($var)
|
||||
{
|
||||
if (null === self::$handler) {
|
||||
$cloner = extension_loaded('symfony_debug') ? new ExtCloner() : new PhpCloner();
|
||||
$cloner = new VarCloner();
|
||||
$dumper = 'cli' === PHP_SAPI ? new CliDumper() : new HtmlDumper();
|
||||
self::$handler = function ($var) use ($cloner, $dumper) {
|
||||
$dumper->dump($cloner->cloneVar($var));
|
||||
|
Reference in New Issue
Block a user