Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[VarDumper] Fix dumping ArrayObject with DumpDataCollector #50960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions 7 src/Symfony/Component/VarDumper/Caster/SplCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ private static function castSplArray($c, array $a, Stub $stub, bool $isNested):
$a = Caster::castObject($c, \get_class($c), method_exists($c, '__debugInfo'), $stub->class);
$c->setFlags($flags);
}
if (\PHP_VERSION_ID < 70400) {
$a[$prefix.'storage'] = $c->getArrayCopy();
}

unset($a["\0ArrayObject\0storage"], $a["\0ArrayIterator\0storage"]);

$a += [
$prefix.'storage' => $c->getArrayCopy(),
$prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST),
$prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getContext(): ?array

$file = $trace[1]['file'];
$line = $trace[1]['line'];
$name = false;
$name = '-' === $file || 'Standard input code' === $file ? 'Standard input code' : false;
$fileExcerpt = false;

for ($i = 2; $i < $this->limit; ++$i) {
Expand Down
10 changes: 2 additions & 8 deletions 10 src/Symfony/Component/VarDumper/Tests/Caster/SplCasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,14 @@ class([123]) extends \ArrayObject {};
$expected = <<<EOTXT
ArrayObject@anonymous {
+"foo": 234
-storage: array:1 [
storage: array:1 [
0 => 123
]
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
iteratorClass: "ArrayIterator"
}
EOTXT;
if (\PHP_VERSION_ID < 70400) {
$expected = str_replace('-storage:', 'storage:', $expected);
}
$this->assertDumpEquals($expected, $var);
}

Expand All @@ -195,16 +192,13 @@ public function testArrayIterator()
$expected = <<<EOTXT
Symfony\Component\VarDumper\Tests\Caster\MyArrayIterator {
-foo: 123
-storage: array:1 [
storage: array:1 [
0 => 234
]
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
}
EOTXT;
if (\PHP_VERSION_ID < 70400) {
$expected = str_replace('-storage:', 'storage:', $expected);
}
$this->assertDumpEquals($expected, $var);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
--TEST--
Test integration with Symfony's DumpDataCollector
--FILE--
<?php
putenv('NO_COLOR=1');

$vendor = __DIR__;
while (!file_exists($vendor.'/vendor')) {
$vendor = dirname($vendor);
}
require $vendor.'/vendor/autoload.php';

use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\VarDumper;

VarDumper::setHandler(function ($var, string $label = null) {
$dumper = new DumpDataCollector();
$cloner = new VarCloner();
$handler = function ($var, string $label = null) use ($dumper, $cloner) {
$var = $cloner->cloneVar($var);
if (null !== $label) {
$var = $var->withContext(['label' => $label]);
}

$dumper->dump($var);
};
VarDumper::setHandler($handler);
$handler($var, $label);
});

$arrayObject = new \ArrayObject();
dump($arrayObject);
$arrayObject['X'] = 'A';
$arrayObject['Y'] = new \ArrayObject(['type' => 'object']);
$arrayObject['Y']['Z'] = 'B';

$arrayIterator = new \ArrayIterator();
dump($arrayIterator);
$arrayIterator['X'] = 'A';
$arrayIterator['Y'] = new \ArrayIterator(['type' => 'object']);
$arrayIterator['Y']['Z'] = 'B';

$recursiveArrayIterator = new \RecursiveArrayIterator();
dump($recursiveArrayIterator);
$recursiveArrayIterator['X'] = 'A';
$recursiveArrayIterator['Y'] = new \RecursiveArrayIterator(['type' => 'object']);
$recursiveArrayIterator['Y']['Z'] = 'B';

--EXPECTF--
%s on line %d:
ArrayObject {#%d
storage: []
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
iteratorClass: "ArrayIterator"
}
%s on line %d:
ArrayIterator {#%d
storage: []
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
}
%s on line %d:
RecursiveArrayIterator {#%d
storage: []
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
}
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/VarDumper/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"require-dev": {
"ext-iconv": "*",
"symfony/console": "^4.4|^5.0|^6.0",
"symfony/http-kernel": "^4.4|^5.0|^6.0",
"symfony/process": "^4.4|^5.0|^6.0",
"symfony/uid": "^5.1|^6.0",
"twig/twig": "^2.13|^3.0.4"
Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/VarDumper/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<testsuites>
<testsuite name="Symfony VarDumper Component Test Suite">
<directory>./Tests/</directory>
<directory suffix=".phpt">./Tests/Dumper/functions/</directory>
</testsuite>
</testsuites>

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.