framework icon indicating copy to clipboard operation
framework copied to clipboard

[9.x] Call object's dump method when passed to global dump

Open avrahamappel opened this issue 3 years ago • 1 comments

Many Laravel classes have dump and dd methods.

It would be nice if these methods would be called when an object of this sort is passed to dd or dump, instead of the default behavior (which can get pretty ugly, especially with things like QueryBuilder, see screenshot below).

Screenshot Screen Shot 2022-11-25 at 11 18 14 AM

This would be especially useful when passing multiple values to the dump methods, i.e.

dump($query1, $query2); // I still want nice output here

This PR adds a new contract, Dumpable, which requires the presence of the dump and dd methods on the implementing class. It also adds a new set of dump and dd functions which replace Symfony's while still being completely backwards compatible.

Note: In order to get Composer to load Illuminate\Support\helpers.php before vendor/symfony/var-dumper/Resources/functions/dump.php while running tests, I had to install funkjedi/composer-include-files (in require-dev only, hope that's ok). In a real application this will probably work out of the box, since both functions will be loaded by Composer, and "L" comes before "S".

avrahamappel avatar Nov 25 '22 01:11 avrahamappel

Looks like using funkjedi/composer-include-files broke an unrelated test. 😞

Also, on second thought maybe we don't want this behavior, as we should leave a way for developers to actually dump the full object. Unless we add that option as a second parameter? 🤔

avrahamappel avatar Nov 25 '22 17:11 avrahamappel

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

taylorotwell avatar Nov 27 '22 19:11 taylorotwell