nette / tracy

šŸ˜Ž Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.
https://tracy.nette.org
Other
1.75k stars 218 forks source link

`Exposer` purges content of some implementations of `Ds\Collection` #560

Closed dakur closed 1 year ago

dakur commented 1 year ago

Version: 2.9.6

Bug Description

When I have Ds\Stack in my application which is inside of some service registered to DIC and I want to render all items in the stack into custom tracy panel, they are all gone.

That's because ContainerPanel from nette/di dumps all services into text representation and part of dumping is a call to Exposer. Exposer has special exposeDsCollection() method for instances of Ds\Collection and runs foreach on the collection. But it doesn't count with the fact that some of Ds\Collection implementation have destructive behavior ā€“ such as Ds\Stack (ref) or Ds\Queue (ref).

Steps To Reproduce

Expected Behavior

To see:

- from presenter
- from panel

as Logger::log() is called in both places. But only from panel is rendered.

Possible Solution

Call $obj->toArray() in exposeDsCollection() method. But I'm not sure if it doesn't have any other consequences, I'm not so experienced in semantics of various data structures and their conversions.

Other possibility can be to differentiate specific Ds\Collection implementations separately.

dg commented 1 year ago

cc @enumag

enumag commented 1 year ago

Hmm... interesting... maybe this could help? https://github.com/nette/tracy/commit/a495ae9ea4dfbde7d1674a46d824cc160a963765

dakur commented 1 year ago

@enumag Yep, that works too.

enumag commented 1 year ago

Considering that toArray() format depends on implementation so it might not always be exactly what we expect I think clone is the better option in this case. It can't change the result and won't destroy the self-destructive implementations.