-
Notifications
You must be signed in to change notification settings - Fork 20
Disable and enable debug bar #21
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
src/PhpDebugBarMiddleware.php
Outdated
@@ -23,6 +23,11 @@ | |||
*/ | |||
final class PhpDebugBarMiddleware implements MiddlewareInterface | |||
{ | |||
const FORCE_KEY = 'X-Debug-Bar'; |
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.
make it public const
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.
Maybe better naming: X-Disable-Debug-Bar
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 case should name X-Enable-Debug-Bar
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.
👍
src/PhpDebugBarMiddleware.php
Outdated
@@ -23,6 +23,11 @@ | |||
*/ | |||
final class PhpDebugBarMiddleware implements MiddlewareInterface | |||
{ | |||
const FORCE_KEY = 'X-Debug-Bar'; | |||
const FORCE_HEADER = self::FORCE_KEY; | |||
const FORCE_COOKIE = self::FORCE_KEY; |
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 really useful, because it repeats the same thing, so we can reuse the same thing, too
src/PhpDebugBarMiddleware.php
Outdated
$isForceEnable = in_array('true', [$forceHeaderValue, $forceCookieValue, $forceAttibuteValue], true); | ||
$isForceDisable = in_array('false', [$forceHeaderValue, $forceCookieValue, $forceAttibuteValue], true); | ||
|
||
if ($isForceDisable || (!$isForceEnable && !$this->isHtmlAccepted($request))) { |
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.
Problem is, some middlewares will just return 302 response (redirect somewhere), and are unaware of the debug bar middleware present. So we need to check for 302 at least additionally.
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.
What about other redirects? https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections
You have right - redirect is possible, but sometimes you want to debug request / response before redirection - this PR allow to do that
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.
That's by using ForceEnable
- cool. Problem is, when a middleware redirects, it's not smart enough to know that this debug bar is present and therefore will probably not set ForceDisable
header.
@prolic ping |
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.
Looks good to me
Alternative fix for #19 #8 and #18 .
This PR allow to force disable or enable PHP Debug Bar using headers, cookies or server request attributes.