Skip to content

[9.x] Register cutInternals casters for particularly noisy objects - #44514

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
inxilpro:add-basic-dumper-defaults
Oct 7, 2022
Merged

taylorotwell merged 2 commits into
laravel:9.xfrom
inxilpro:add-basic-dumper-defaults

Conversation

@inxilpro

@inxilpro inxilpro commented Oct 7, 2022 •

Copy link
Copy Markdown
Contributor

This is a much smaller version of #44408 that addresses the major pain point of using dd() in Laravel—dumping an object that holds a reference to the container (or another potentially large object that you don't actually care about from a debugging context).

By default, Symfony registers the StubCaster::cutInternals caster for many internal classes, including the Symfony container and event dispatcher. This caster cuts down the object when dumping, but only if it's nested. This PR registers that same caster for a couple of Laravel interfaces that tend to be very large.

For example, currently if you were to call dd() on an instance of the Router, your output will include include about 500 lines showing the Dispatcher and another 500 lines showing the Container before you get anywhere near the $routes or other values that you're likely trying to view.

After this PR, those 1000 lines are collapsed to:

Illuminate\Routing\Router {
  #events: Illuminate\Events\Dispatcher { …20 }
  #container: Illuminate\Container\Container { …19 }
}

The cutInternals caster only applies if the object is nested, though. So if you call dd() directly on the container or event dispatcher, the entire object will be dumped.

This feels like 70% of the benefits of Laravel Dumper for about 1% of the maintenance cost.

@inxilpro
inxilpro marked this pull request as ready for review October 7, 2022 20:52
@inxilpro inxilpro changed the title [9.x] Add register cutInternals casters for particularly noisy objects [9.x] Register cutInternals casters for particularly noisy objects Oct 7, 2022
@taylorotwell
taylorotwell merged commit dfb215e into laravel:9.x Oct 7, 2022
@taylorotwell

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants