Skip to content

Commit

Permalink
Dumper: added support for ArrayObject properties [Closes #413]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 13, 2020
1 parent 9e525fe commit 13cfb6d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Tracy/Dumper/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
14 changes: 14 additions & 0 deletions src/Tracy/Dumper/Exposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down
22 changes: 22 additions & 0 deletions tests/Tracy/Dumper.toHtml().specials.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,25 @@ Assert::match('<pre class="tracy-dump"><span class="tracy-toggle"><span class="t
</div></div></pre>', Dumper::toHtml($objStorage));

Assert::same($key, $objStorage->key());


// ArrayObject
$obj = new ArrayObject(['a' => 1, 'b' => 2]);
Assert::match('<pre class="tracy-dump"><span class="tracy-toggle"><span class="tracy-dump-object">ArrayObject</span> <span class="tracy-dump-hash">#%d%</span></span>
<div><span class="tracy-dump-indent"> </span><span class="tracy-dump-key">storage</span> <span class="tracy-dump-visibility">private</span> => <span class="tracy-toggle"><span class="tracy-dump-array">array</span> (2)</span>
<div><span class="tracy-dump-indent"> | </span><span class="tracy-dump-key">a</span> => <span class="tracy-dump-number">1</span>
<span class="tracy-dump-indent"> | </span><span class="tracy-dump-key">b</span> => <span class="tracy-dump-number">2</span>
</div></div></pre>', Dumper::toHtml($obj));

class ArrayObjectChild extends ArrayObject
{
public $prop = 123;
}

$obj = new ArrayObjectChild(['a' => 1, 'b' => 2]);
Assert::match('<pre class="tracy-dump"><span class="tracy-toggle"><span class="tracy-dump-object">ArrayObjectChild</span> <span class="tracy-dump-hash">#%d%</span></span>
<div><span class="tracy-dump-indent"> </span><span class="tracy-dump-key">prop</span> => <span class="tracy-dump-number">123</span>
<span class="tracy-dump-indent"> </span><span class="tracy-dump-key">storage</span> <span class="tracy-dump-visibility">private</span> => <span class="tracy-toggle"><span class="tracy-dump-array">array</span> (2)</span>
<div><span class="tracy-dump-indent"> | </span><span class="tracy-dump-key">a</span> => <span class="tracy-dump-number">1</span>
<span class="tracy-dump-indent"> | </span><span class="tracy-dump-key">b</span> => <span class="tracy-dump-number">2</span>
</div></div></pre>', Dumper::toHtml($obj));
22 changes: 22 additions & 0 deletions tests/Tracy/Dumper.toText().specials.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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));

0 comments on commit 13cfb6d

Please sign in to comment.