From 13cfb6defbcf9649a053f457a11e408ec6c5f688 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 12 Apr 2020 23:45:19 +0200 Subject: [PATCH] Dumper: added support for ArrayObject properties [Closes #413] --- src/Tracy/Dumper/Dumper.php | 1 + src/Tracy/Dumper/Exposer.php | 14 ++++++++++++++ tests/Tracy/Dumper.toHtml().specials.phpt | 22 ++++++++++++++++++++++ tests/Tracy/Dumper.toText().specials.phpt | 22 ++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/src/Tracy/Dumper/Dumper.php b/src/Tracy/Dumper/Dumper.php index 576bae512..7d8175b98 100644 --- a/src/Tracy/Dumper/Dumper.php +++ b/src/Tracy/Dumper/Dumper.php @@ -63,6 +63,7 @@ class Dumper /** @var array */ public static $objectExporters = [ 'Closure' => [Exposer::class, 'exposeClosure'], + 'ArrayObject' => [Exposer::class, 'exposeArrayObject'], 'SplFileInfo' => [Exposer::class, 'exposeSplFileInfo'], 'SplObjectStorage' => [Exposer::class, 'exposeSplObjectStorage'], '__PHP_Incomplete_Class' => [Exposer::class, 'exposePhpIncompleteClass'], diff --git a/src/Tracy/Dumper/Exposer.php b/src/Tracy/Dumper/Exposer.php index 8b1ea733f..35874ce71 100644 --- a/src/Tracy/Dumper/Exposer.php +++ b/src/Tracy/Dumper/Exposer.php @@ -32,6 +32,20 @@ public static function exposeClosure(\Closure $obj): array } + public static function exposeArrayObject(\ArrayObject $obj): array + { + $res = []; + $flags = $obj->getFlags(); + if (!($flags & \ArrayObject::STD_PROP_LIST)) { + $obj->setFlags(\ArrayObject::STD_PROP_LIST); + $res = (array) $obj; + $obj->setFlags($flags); + } + $res["\x00\x00storage"] = $obj->getArrayCopy(); + return $res; + } + + public static function exposeSplFileInfo(\SplFileInfo $obj): array { return ['path' => $obj->getPathname()]; diff --git a/tests/Tracy/Dumper.toHtml().specials.phpt b/tests/Tracy/Dumper.toHtml().specials.phpt index 0344407b9..c19804916 100644 --- a/tests/Tracy/Dumper.toHtml().specials.phpt +++ b/tests/Tracy/Dumper.toHtml().specials.phpt @@ -60,3 +60,25 @@ Assert::match('
ArrayObject #%d%
+
storage private => array (2) +
| a => 1 + | b => 2 +
', Dumper::toHtml($obj)); + +class ArrayObjectChild extends ArrayObject +{ + public $prop = 123; +} + +$obj = new ArrayObjectChild(['a' => 1, 'b' => 2]); +Assert::match('
ArrayObjectChild #%d%
+
prop => 123 + storage private => array (2) +
| a => 1 + | b => 2 +
', Dumper::toHtml($obj)); diff --git a/tests/Tracy/Dumper.toText().specials.phpt b/tests/Tracy/Dumper.toText().specials.phpt index 07d676d0e..8af0bcf96 100644 --- a/tests/Tracy/Dumper.toText().specials.phpt +++ b/tests/Tracy/Dumper.toText().specials.phpt @@ -58,3 +58,25 @@ Assert::match('SplObjectStorage #%d% ', Dumper::toText($objStorage)); Assert::same($key, $objStorage->key()); + + +// ArrayObject +$obj = new ArrayObject(['a' => 1, 'b' => 2]); +Assert::match('ArrayObject #%d% + storage private => array (2) + | a => 1 + | b => 2 +', Dumper::toText($obj)); + +class ArrayObjectChild extends ArrayObject +{ + public $prop = 123; +} + +$obj = new ArrayObjectChild(['a' => 1, 'b' => 2]); +Assert::match('ArrayObjectChild #%d% + prop => 123 + storage private => array (2) + | a => 1 + | b => 2 +', Dumper::toText($obj));