Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Disable and enable debug bar#21

Merged
snapshotpl merged 12 commits intomasterphp-middleware/phpdebugbar:masterfrom
disable-enable-barphp-middleware/phpdebugbar:disable-enable-barCopy head branch name to clipboard
Apr 26, 2018
Merged

Disable and enable debug bar#21
snapshotpl merged 12 commits intomasterphp-middleware/phpdebugbar:masterfrom
disable-enable-barphp-middleware/phpdebugbar:disable-enable-barCopy head branch name to clipboard

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.

*/
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.

👍

{
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.