Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 7, 2022

Conversation

inxilpro
Copy link
Contributor

@inxilpro inxilpro commented Oct 7, 2022

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
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