Skip to content

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

Merged
merged 12 commits into from
Apr 26, 2018
Merged

Disable and enable debug bar #21

merged 12 commits into from
Apr 26, 2018

Conversation

snapshotpl
Copy link
Member

@snapshotpl snapshotpl commented Apr 17, 2018

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.

@@ -23,6 +23,11 @@
*/
final class PhpDebugBarMiddleware implements MiddlewareInterface
{
const FORCE_KEY = 'X-Debug-Bar';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it public const

Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -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;
Copy link
Contributor

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

$isForceEnable = in_array('true', [$forceHeaderValue, $forceCookieValue, $forceAttibuteValue], true);
$isForceDisable = in_array('false', [$forceHeaderValue, $forceCookieValue, $forceAttibuteValue], true);

if ($isForceDisable || (!$isForceEnable && !$this->isHtmlAccepted($request))) {
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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.

@snapshotpl
Copy link
Member Author

@prolic ping

Copy link
Contributor

@prolic prolic left a 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

@snapshotpl snapshotpl merged commit 6c2c461 into master Apr 26, 2018
@snapshotpl snapshotpl deleted the disable-enable-bar branch February 22, 2022 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants