Disable and enable debug bar#21
Disable and enable debug bar#21snapshotpl merged 12 commits intomasterphp-middleware/phpdebugbar:masterfrom
Conversation
src/PhpDebugBarMiddleware.php
Outdated
| */ | ||
| final class PhpDebugBarMiddleware implements MiddlewareInterface | ||
| { | ||
| const FORCE_KEY = 'X-Debug-Bar'; |
There was a problem hiding this comment.
Maybe better naming: X-Disable-Debug-Bar
There was a problem hiding this comment.
this case should name X-Enable-Debug-Bar
src/PhpDebugBarMiddleware.php
Outdated
| { | ||
| 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.
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.
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.
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.
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 |
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.