Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/var-dumper
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.3.8
Choose a base ref
...
head repository: symfony/var-dumper
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.3.10
Choose a head ref
  • 9 commits
  • 8 files changed
  • 6 contributors

Commits on Oct 2, 2021

  1. Copy the full SHA
    0f8c227 View commit details

Commits on Oct 5, 2021

  1. Merge branch '4.4' into 5.3

    * 4.4:
      [VarDumper] Fix handling of "new" in initializers on PHP 8.1
    nicolas-grekas committed Oct 5, 2021
    Copy the full SHA
    b43c51f View commit details

Commits on Oct 18, 2021

  1. added missing thai translations

    shreyadenny authored and fabpot committed Oct 18, 2021
    Copy the full SHA
    2a50705 View commit details

Commits on Oct 19, 2021

  1. Merge branch '4.4' into 5.3

    * 4.4: (29 commits)
      fix: Improve FR validators translation
      Add swedish translation for issue #43458
      [HttpClient] fix collecting debug info on destruction of CurlResponse
      Fix CS
      added missing thai translations
      Add missing translations for Chinese (zh_TW)
      [DependencyInjection] fix "url" env var processor
      update translation
      Remove untranslated translation for Afrikaans
      [Validator] Add missing validator polish translation
      [Security,Validator] Added missing Latvian translations #41053
      Add the missing translations for Indonesian (id)
      [Validator] Add missing Lithuanian translation
      [Validator] Add missing Czech translation
      replace "ispravna" with "važeća" in translating "valid HTML/CSS"
      added missing translation for galician
      Add missing translation in Vietnamese
      Add missing translation in Bulgarian
      added missing translations for portuguese [#43450]
      Add missing validator slovak translation
      ...
    derrabus committed Oct 19, 2021
    Copy the full SHA
    23a50d1 View commit details

Commits on Oct 25, 2021

  1. Copy the full SHA
    52d5b02 View commit details
  2. cs fix

    nicolas-grekas committed Oct 25, 2021
    Copy the full SHA
    5dbb2ab View commit details
  3. Merge branch '4.4' into 5.3

    * 4.4:
      cs fix
      [VarDumper] Fix dumping twig templates found in exceptions
    nicolas-grekas committed Oct 25, 2021
    Copy the full SHA
    7867c56 View commit details
  4. Update README.md

    94noni authored Oct 25, 2021
    Copy the full SHA
    50286e2 View commit details

Commits on Oct 26, 2021

  1. Merge branch '4.4' into 5.3

    * 4.4:
      Use GitHub issue form templates
      Add missing translations for Persian (fa)
      Add the missing translations for Bahasa Indonesia (id)
      Update README.md
      Fix deprecations on PHP 8.2
    xabbuh committed Oct 26, 2021
    Copy the full SHA
    875432a View commit details
30 changes: 18 additions & 12 deletions Caster/ExceptionCaster.php
Original file line number Diff line number Diff line change
@@ -214,18 +214,24 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, boo

if (is_file($f['file']) && 0 <= self::$srcContext) {
if (!empty($f['class']) && (is_subclass_of($f['class'], 'Twig\Template') || is_subclass_of($f['class'], 'Twig_Template')) && method_exists($f['class'], 'getDebugInfo')) {
$template = $f['object'] ?? unserialize(sprintf('O:%d:"%s":0:{}', \strlen($f['class']), $f['class']));

$ellipsis = 0;
$templateSrc = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : '');
$templateInfo = $template->getDebugInfo();
if (isset($templateInfo[$f['line']])) {
if (!method_exists($template, 'getSourceContext') || !is_file($templatePath = $template->getSourceContext()->getPath())) {
$templatePath = null;
}
if ($templateSrc) {
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, 'twig', $templatePath, $f);
$srcKey = ($templatePath ?: $template->getTemplateName()).':'.$templateInfo[$f['line']];
$template = null;
if (isset($f['object'])) {
$template = $f['object'];
} elseif ((new \ReflectionClass($f['class']))->isInstantiable()) {
$template = unserialize(sprintf('O:%d:"%s":0:{}', \strlen($f['class']), $f['class']));
}
if (null !== $template) {
$ellipsis = 0;
$templateSrc = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : '');
$templateInfo = $template->getDebugInfo();
if (isset($templateInfo[$f['line']])) {
if (!method_exists($template, 'getSourceContext') || !is_file($templatePath = $template->getSourceContext()->getPath())) {
$templatePath = null;
}
if ($templateSrc) {
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, 'twig', $templatePath, $f);
$srcKey = ($templatePath ?: $template->getTemplateName()).':'.$templateInfo[$f['line']];
}
}
}
}
2 changes: 2 additions & 0 deletions Caster/ReflectionCaster.php
Original file line number Diff line number Diff line change
@@ -384,6 +384,8 @@ public static function getSignature(array $a)
$signature .= 10 > \strlen($v) && !str_contains($v, '\\') ? "'{$v}'" : "'…".\strlen($v)."'";
} elseif (\is_bool($v)) {
$signature .= $v ? 'true' : 'false';
} elseif (\is_object($v)) {
$signature .= 'new '.substr(strrchr('\\'.get_debug_type($v), '\\'), 1);
} else {
$signature .= $v;
}
23 changes: 17 additions & 6 deletions Caster/XmlReaderCaster.php
Original file line number Diff line number Diff line change
@@ -44,6 +44,22 @@ class XmlReaderCaster

public static function castXmlReader(\XMLReader $reader, array $a, Stub $stub, bool $isNested)
{
try {
$properties = [
'LOADDTD' => @$reader->getParserProperty(\XMLReader::LOADDTD),
'DEFAULTATTRS' => @$reader->getParserProperty(\XMLReader::DEFAULTATTRS),
'VALIDATE' => @$reader->getParserProperty(\XMLReader::VALIDATE),
'SUBST_ENTITIES' => @$reader->getParserProperty(\XMLReader::SUBST_ENTITIES),
];
} catch (\Error $e) {
$properties = [
'LOADDTD' => false,
'DEFAULTATTRS' => false,
'VALIDATE' => false,
'SUBST_ENTITIES' => false,
];
}

$props = Caster::PREFIX_VIRTUAL.'parserProperties';
$info = [
'localName' => $reader->localName,
@@ -57,12 +73,7 @@ public static function castXmlReader(\XMLReader $reader, array $a, Stub $stub, b
'value' => $reader->value,
'namespaceURI' => $reader->namespaceURI,
'baseURI' => $reader->baseURI ? new LinkStub($reader->baseURI) : $reader->baseURI,
$props => [
'LOADDTD' => $reader->getParserProperty(\XMLReader::LOADDTD),
'DEFAULTATTRS' => $reader->getParserProperty(\XMLReader::DEFAULTATTRS),
'VALIDATE' => $reader->getParserProperty(\XMLReader::VALIDATE),
'SUBST_ENTITIES' => $reader->getParserProperty(\XMLReader::SUBST_ENTITIES),
],
$props => $properties,
];

if ($info[$props] = Caster::filter($info[$props], Caster::EXCLUDE_EMPTY, [], $count)) {
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ VarDumper Component

The VarDumper component provides mechanisms for walking through any arbitrary
PHP variable. It provides a better `dump()` function that you can use instead
of `var_dump`.
of `var_dump()`.

Resources
---------
60 changes: 42 additions & 18 deletions Tests/Caster/ExceptionCasterTest.php
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
use Symfony\Component\VarDumper\Caster\Caster;
use Symfony\Component\VarDumper\Caster\ExceptionCaster;
use Symfony\Component\VarDumper\Caster\FrameStub;
use Symfony\Component\VarDumper\Caster\TraceStub;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
@@ -44,15 +45,15 @@ public function testDefaultSettings()
#message: "foo"
#code: 0
#file: "%sExceptionCasterTest.php"
#line: 28
#line: %d
trace: {
%s%eTests%eCaster%eExceptionCasterTest.php:28 {
%s%eTests%eCaster%eExceptionCasterTest.php:%d {
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestException($msg, &$ref = null)
› {
› return new \Exception(''.$msg);
› }
}
%s%eTests%eCaster%eExceptionCasterTest.php:40 { …}
%s%eTests%eCaster%eExceptionCasterTest.php:%d { …}
%A
EODUMP;

@@ -66,13 +67,13 @@ public function testSeek()

$expectedDump = <<<'EODUMP'
{
%s%eTests%eCaster%eExceptionCasterTest.php:28 {
%s%eTests%eCaster%eExceptionCasterTest.php:%d {
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestException($msg, &$ref = null)
› {
› return new \Exception(''.$msg);
› }
}
%s%eTests%eCaster%eExceptionCasterTest.php:65 { …}
%s%eTests%eCaster%eExceptionCasterTest.php:%d { …}
%A
EODUMP;

@@ -89,15 +90,15 @@ public function testNoArgs()
#message: "1"
#code: 0
#file: "%sExceptionCasterTest.php"
#line: 28
#line: %d
trace: {
%sExceptionCasterTest.php:28 {
%sExceptionCasterTest.php:%d {
Symfony\Component\VarDumper\Tests\Caster\ExceptionCasterTest->getTestException($msg, &$ref = null)
› {
› return new \Exception(''.$msg);
› }
}
%s%eTests%eCaster%eExceptionCasterTest.php:84 { …}
%s%eTests%eCaster%eExceptionCasterTest.php:%d { …}
%A
EODUMP;

@@ -114,16 +115,40 @@ public function testNoSrcContext()
#message: "1"
#code: 0
#file: "%sExceptionCasterTest.php"
#line: 28
#line: %d
trace: {
%s%eTests%eCaster%eExceptionCasterTest.php:28
%s%eTests%eCaster%eExceptionCasterTest.php:%d
%s%eTests%eCaster%eExceptionCasterTest.php:%d
%A
EODUMP;

$this->assertDumpMatchesFormat($expectedDump, $e);
}

public function testShouldReturnTraceForConcreteTwigWithError()
{
require_once \dirname(__DIR__).'/Fixtures/Twig.php';

$innerExc = (new \__TwigTemplate_VarDumperFixture_u75a09(null, __FILE__))->provideError();
$nestingWrapper = new \stdClass();
$nestingWrapper->trace = new TraceStub($innerExc->getTrace());

$expectedDump = <<<'EODUMP'
{
+"trace": {
%sTwig.php:%d {
AbstractTwigTemplate->provideError()
› {
› return $this->createError();
› }
}
%sExceptionCasterTest.php:%d { …}
%A
EODUMP;

$this->assertDumpMatchesFormat($expectedDump, $nestingWrapper);
}

public function testHtmlDump()
{
if (ini_get('xdebug.file_link_format') || get_cfg_var('xdebug.file_link_format')) {
@@ -146,10 +171,10 @@ public function testHtmlDump()
#<span class=sf-dump-protected title="Protected property">code</span>: <span class=sf-dump-num>0</span>
#<span class=sf-dump-protected title="Protected property">file</span>: "<span class=sf-dump-str title="%sExceptionCasterTest.php
%d characters"><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%s%eVarDumper</span><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%e</span>Tests%eCaster%eExceptionCasterTest.php</span>"
#<span class=sf-dump-protected title="Protected property">line</span>: <span class=sf-dump-num>28</span>
#<span class=sf-dump-protected title="Protected property">line</span>: <span class=sf-dump-num>%d</span>
<span class=sf-dump-meta>trace</span>: {<samp data-depth=2 class=sf-dump-compact>
<span class=sf-dump-meta title="%sExceptionCasterTest.php
Stack level %d."><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%s%eVarDumper</span><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%e</span>Tests%eCaster%eExceptionCasterTest.php</span>:<span class=sf-dump-num>28</span>
Stack level %d."><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%s%eVarDumper</span><span class="sf-dump-ellipsis sf-dump-ellipsis-path">%e</span>Tests%eCaster%eExceptionCasterTest.php</span>:<span class=sf-dump-num>%d</span>
&hellip;%d
</samp>}
</samp>}
@@ -169,12 +194,12 @@ public function testFrameWithTwig()
$f = [
new FrameStub([
'file' => \dirname(__DIR__).'/Fixtures/Twig.php',
'line' => 20,
'line' => 33,
'class' => '__TwigTemplate_VarDumperFixture_u75a09',
]),
new FrameStub([
'file' => \dirname(__DIR__).'/Fixtures/Twig.php',
'line' => 21,
'line' => 34,
'class' => '__TwigTemplate_VarDumperFixture_u75a09',
'object' => new \__TwigTemplate_VarDumperFixture_u75a09(null, __FILE__),
]),
@@ -186,7 +211,7 @@ public function testFrameWithTwig()
class: "__TwigTemplate_VarDumperFixture_u75a09"
src: {
%sTwig.php:1 {
%s
› foo bar
› twig source
}
@@ -201,12 +226,11 @@ class: "__TwigTemplate_VarDumperFixture_u75a09"
%sExceptionCasterTest.php:2 {
› foo bar
› twig source
%s
}
}
}
]

EODUMP;

$this->assertDumpMatchesFormat($expectedDump, $f);
@@ -221,7 +245,7 @@ public function testExcludeVerbosity()
#message: "foo"
#code: 0
#file: "%sExceptionCasterTest.php"
#line: 28
#line: %d
}
EODUMP;

21 changes: 21 additions & 0 deletions Tests/Caster/ReflectionCasterTest.php
Original file line number Diff line number Diff line change
@@ -602,6 +602,27 @@ public function testGenerator()
$this->assertDumpMatchesFormat($expectedDump, $generator);
}

/**
* @requires PHP 8.1
*/
public function testNewInInitializer()
{
$f = eval('return function ($a = new stdClass()) {};');
$line = __LINE__ - 1;

$this->assertDumpMatchesFormat(
<<<EOTXT
Closure(\$a = new stdClass) {
class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
this: Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest { …}
file: "%sReflectionCasterTest.php($line) : eval()'d code"
line: "1 to 1"
}
EOTXT
, $f
);
}

/**
* @requires PHP 8
*/
14 changes: 14 additions & 0 deletions Tests/Caster/XmlReaderCasterTest.php
Original file line number Diff line number Diff line change
@@ -245,4 +245,18 @@ public function provideNodes()
],
];
}

public function testWithUninitializedXMLReader()
{
$this->reader = new \XmlReader();

$expectedDump = <<<'EODUMP'
XMLReader {
+nodeType: NONE
…13
}
EODUMP;

$this->assertDumpMatchesFormat($expectedDump, $this->reader);
}
}
17 changes: 15 additions & 2 deletions Tests/Fixtures/Twig.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
<?php

abstract class AbstractTwigTemplate extends Twig\Template
{
private function createError()
{
return new \RuntimeException('Manually triggered error.');
}

public function provideError()
{
return $this->createError();
}
}

/* foo.twig */
class __TwigTemplate_VarDumperFixture_u75a09 extends Twig\Template
class __TwigTemplate_VarDumperFixture_u75a09 extends AbstractTwigTemplate
{
private $path;

@@ -28,7 +41,7 @@ public function getTemplateName()

public function getDebugInfo()
{
return [20 => 1, 21 => 2];
return [33 => 1, 34 => 2];
}

public function getSourceContext()