-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] Easy server dumper registration #26695
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
@@ -38,11 +40,27 @@ public static function dump($var) | |||
return call_user_func(self::$handler, $var); | |||
} | |||
|
|||
public static function setHandler(callable $callable = null) | |||
public static function setHandler(callable $callable = null, bool $lock = false): ?callable |
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.
Right now, this is a BC break because the method isn't final. Just waiting more feedback about the process.
} | ||
|
||
$fileLinkFormatter = class_exists(FileLinkFormatter::class) ? new FileLinkFormatter(null, $requestStack ?? null, $projectDir) : null; | ||
$contextProviders = array( |
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.
There is a bug, you erase the $contextProviders that you define on line 63
you must do $contextProviders += array(
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.
Oops. Good catch. Refactoring issue. Thank you 👍
@ogizanagi there is a fail on the test :/ (yes I want to use the content of your PR ^^) |
@kardagan : I rebased the PR on master to resolve a conflict, but previous failures were unrelated actually. Current build is passing. However, I do get a failure on EDIT: Hmm, actually it's just failing when setting the |
So I'd suggest to mark the @kardagan : Did you happen to try this PR? Seems useful to you? |
@ogizanagi I don't use your PR, but I copy/past the code in your register method to init my conf. My lone comment is on the paramters, I think it's would be more simple to give the Request in parameter than ask a contextProvider array. And in the registier do that.
|
Yes, I guess we need to find the right balance between flexibility and ease to register it. ServerDumper::register($host, true, [
'request' => ServerDumper::getDefaultContextProviders($request)['request'],
]) which still appears to be the most flexible to me for now 🤔 |
{ | ||
$lock = \func_num_args() > 1 ? func_get_arg(1) : false; |
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.
I think we can do without this change: just call the method twice to restore
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.
Not sure to understand what you meant?
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.
I meant we should be able to make this work without changing this method at all.
After discussing a bit with @nicolas-grekas , I've chosen to remove the This is ready (to me). |
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.
This is quite dirty code, with a behavior that varies depending on the dependencies you have. This is glue code, so why not. But I feel like I'd need more explanation, example, doc(blocks) to explain what's the purpose, how to use, so that we get convinced we need this is core (vs e.g. putting this as is in the doc and tell ppl to copy/paste.)
*/ | ||
public static function register(string $host = null, array $contextProviders = array()): ?callable | ||
{ | ||
$contextProviders += self::getDefaultContextProviders(); |
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.
Having getDefaultContextProviders called with self:: and with no argument here + that the method is final means there is no way to override the default context providers here. This might be fine (is it?) but then, what's the prupose of a standalone getDefaultContextProviders method?
Closing for now as this is not getting as much traction as I thought it would for small PHP projects. |
Much traction from whom? If this is from the core team, that's just because it does not seem to be ready. |
@fabpot : Not at all :) (Sorry if it was misinterpreted). Just considering we do not have much feedback from outside people regarding this for now. |
…nagi) This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [VarDumper] Add VAR_DUMPER_FORMAT=server format | Q | A | ------------- | --- | Branch? | master<!-- see below --> | Bug fix? | no | New feature? | yes<!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #35801 <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | TODO <!-- required for new features --> 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~~ we prevent registering another handler as soon as the `VAR_DUMPER_FORMAT` env var is set, 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 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: - #26695 - #26696 Commits ------- 82df6db [VarDumper] Add VAR_DUMPER_FORMAT=server format
Following #26654, this is another step aiming to ease usage of the server dumper feature in any situation.
The new
ServerDumper::register()
method allows to easily configure & set the ServerDumper as main handler in one line.The new
$lock
flag might not be the ideal solution, but is answering issues when registering the server dumper as main handler but being overwritten by another process (like in tests for instance. PR acting as a real use-case incoming => #26696).Anyway, I'm open to any suggestion :)