From 86eeb974b031a50e1ac9e1fabf5644f005adeacd Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 28 Mar 2023 12:42:32 +0200 Subject: [PATCH] Exposer: recognizes virtual properties of native classes '(array) $obj' and 'get_mangled_object_vars($obj)' differ in that the function does not return a virtual properties. So it can be used to recognize them. --- src/Tracy/Dumper/Exposer.php | 6 ++- tests/Tracy/Dumper.toHtml().specials.phpt | 50 +++++++++++++++++++++++ tests/Tracy/Dumper.toText().specials.phpt | 19 +++++++-- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/Tracy/Dumper/Exposer.php b/src/Tracy/Dumper/Exposer.php index bc7220774..04a5d4f60 100644 --- a/src/Tracy/Dumper/Exposer.php +++ b/src/Tracy/Dumper/Exposer.php @@ -19,9 +19,13 @@ final class Exposer { public static function exposeObject(object $obj, Value $value, Describer $describer): void { - $values = (array) $obj; + $values = get_mangled_object_vars($obj); $props = self::getProperties($obj::class); + foreach (array_diff_key((array) $obj, $values) as $k => $v) { + $describer->addPropertyTo($value, (string) $k, $v); + } + foreach (array_diff_key($values, $props) as $k => $v) { $describer->addPropertyTo( $value, diff --git a/tests/Tracy/Dumper.toHtml().specials.phpt b/tests/Tracy/Dumper.toHtml().specials.phpt index a4217a3a7..33f7c65c8 100644 --- a/tests/Tracy/Dumper.toHtml().specials.phpt +++ b/tests/Tracy/Dumper.toHtml().specials.phpt @@ -145,3 +145,53 @@ Assert::match( XX, Dumper::toHtml($obj), ); + + +// ArrayIterator +$obj = new ArrayIterator(['a', 'b']); +Assert::match( + <<<'XX' +
ArrayIterator #%d%
+		
0: 'a' + 1: 'b' +
+ XX, + Dumper::toHtml($obj), +); + + +// DateTime +$obj = new DateTime('1978-01-23'); +Assert::match( + <<<'XX' +
DateTime #%d%
+		
date: '1978-01-23 00:00:00.000000' + timezone_type: 3 + timezone: '%a%' +
+ XX, + Dumper::toHtml($obj), +); + + +// Tracy\Dumper\Value +$obj = new Tracy\Dumper\Value(Tracy\Dumper\Value::TypeText, 'ahoj'); +Assert::match( + <<<'XX' +
Tracy\Dumper\Value #%d%
+		
type: 'text' + value: 'ahoj' + length: null + depth: null + id: null + holder: unset + items: null + editor: null + collapsed: null +
+ XX, + Dumper::toHtml($obj), +); diff --git a/tests/Tracy/Dumper.toText().specials.phpt b/tests/Tracy/Dumper.toText().specials.phpt index ecda7d269..adb93d3c4 100644 --- a/tests/Tracy/Dumper.toText().specials.phpt +++ b/tests/Tracy/Dumper.toText().specials.phpt @@ -107,12 +107,25 @@ Assert::match(<<<'XX' // ArrayIterator -$obj = new ArrayIterator(['a' => 1, 'b' => 2]); +$obj = new ArrayIterator(['a', 'b']); Assert::match( <<<'XX' ArrayIterator #%d% - a: 1 - b: 2 + 0: 'a' + 1: 'b' + XX, + Dumper::toText($obj), +); + + +// DateTime +$obj = new DateTime('1978-01-23'); +Assert::match( + <<<'XX' + DateTime #%d% + date: '1978-01-23 00:00:00.000000' + timezone_type: %d% + timezone: '%a%' XX, Dumper::toText($obj), );