-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] New env var to select the dump format #25125
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
Conversation
Indeed I've missed #23831 and it looks very interesting but I don't think that it addresses the same use case.
Yes it's intended (just as do the CLI formatter by default). |
It's always quick & dirty ;) Just trying to make it a bit more clean. But of course I also understand how a simple env var to prepend is convenient for punctual dumps, so I'm not against this feature at all. |
@dunglas I also think you can replace |
@theofidry unfortunately I can't because my default browser is Firefox, and Firefox is very bad at reusing an existing instance (it usually ends up by an error). |
open -a "Google Chrome" tmp.html ? 😄 |
@ogizanagi great thanks! This one works with Firefox too (but why, it's another topic). |
Are you ok to merge this one @symfony/deciders? I miss it almost every day 😄. |
e338850
to
fde9b7b
Compare
@@ -29,7 +29,7 @@ public static function dump($var) | |||
{ | |||
if (null === self::$handler) { | |||
$cloner = new VarCloner(); | |||
$dumper = in_array(PHP_SAPI, array('cli', 'phpdbg')) ? new CliDumper() : new HtmlDumper(); | |||
$dumper = in_array(PHP_SAPI, array('cli', 'phpdbg')) && !($_SERVER['VAR_DUMPER_HTML'] ?? false) ? new CliDumper() : new HtmlDumper(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could work both ways: forcing CLI instead of HTML, for API responses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Note: it's related to #23442 |
PR tweaked to be able to select any format, env var renamed to |
I thinks I only works when using the dumper directly.
|
@lyrixx done |
3b7a695
to
536125a
Compare
Thank you @dunglas. |
…glas) This PR was squashed before being merged into the 4.2-dev branch (closes #25125). Discussion ---------- [VarDumper] New env var to select the dump format | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | todo This PR introduces a new environment variable that can be used to force `dump()` to generate HTML even in CLI, or CLI even in a web context. It allows to dump large objects when debugging a command, to open the resulting HTML in a browser, and to benefit of the nice JS UI (folded by default, search engine...). Example usage: VAR_DUMPER_FORMAT=html vendor/bin/behat > tmp.html; open -a firefox tmp.html VAR_DUMPER_FORMAT=cli vendor/bin/behat > tmp.txt Commits ------- 536125a [VarDumper] New env var to select the dump format
I've created symfony/symfony-docs#10275 to document this new feature. But please, don't forget to create a PR, or at least an issue, for every new feature. Thanks! |
This PR introduces a new environment variable that can be used to force
dump()
to generate HTML even in CLI, or CLI even in a web context.It allows to dump large objects when debugging a command, to open the resulting HTML in a browser, and to benefit of the nice JS UI (folded by default, search engine...).
Example usage: