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

[VarDumper] Add VAR_DUMPER_FORMAT=server format #35967

Open
wants to merge 1 commit into
base: master
from

Conversation

@ogizanagi
Copy link
Member

ogizanagi commented Mar 5, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #35801
License MIT
Doc PR TODO

This PR follows discussion in #35801 and adds support for a server value for the existing VAR_DUMPER_FORMAT env var.

It comes as well with two more things:

  • the handler is registered as soon as the VAR_DUMPER_FORMAT env var is detected instead of checking if there was a previous handler (which could make this env var useless in some conditions where the handler was already set by another "process")
  • the handler registered this way is locked, meaning it cannot be replaced. This prevents another "process" to takeover dump handling while undesired. E.g: a phpunit functional test booting the kernel to call an endpoint => the handler is replaced. It's (in a sense) a satisfying alternative to #26696

This PR means anyone can use dump with a server in any context, without changing a single line of code in the project by:

  • starting the server using ./vendor/bin/var-dump-server --format=html > dumps.html
  • using the env var: VAR_DUMPER_FORMAT=server [your-cli-command]

Previous related PRs:

@ogizanagi ogizanagi force-pushed the ogizanagi:var-dumper/server-format-env-var branch from c1ad0e4 to 2e6751a Mar 5, 2020
@ogizanagi ogizanagi added this to the next milestone Mar 6, 2020
@ogizanagi ogizanagi force-pushed the ogizanagi:var-dumper/server-format-env-var branch from 2e6751a to 2306a2d Mar 7, 2020
@@ -11,6 +11,11 @@

use Symfony\Component\VarDumper\VarDumper;

// Register & lock the handler with expected format as soon as the env var was set:
if (isset($_SERVER['VAR_DUMPER_FORMAT'])) {

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Mar 31, 2020

Member

this is too early for being compatible with .env...

This comment has been minimized.

Copy link
@ogizanagi

ogizanagi Mar 31, 2020

Author Member

You're right....but I really didn't have this use-case in mind.

My opinion here is that using the VAR_DUMPER_FORMAT is not a .env file use-case at all. You'll use it in CLI to get the single format you expected, whatever the stack does behind. We need this to be registered as soon as possible to ensure the format is locked and cannot be replaced by the stack. Otherwise setHandler can be called before the very first dump and take precedence over expected format.

So...what about making setHandler a noop instead as soon as the VAR_DUMPER_FORMAT var is set (removing the lock concept by the same way)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.