Download the PHP package redbitcz/debug-mode-enabler without Composer
On this page you can find all versions of the php package redbitcz/debug-mode-enabler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download redbitcz/debug-mode-enabler
More information about redbitcz/debug-mode-enabler
Files in redbitcz/debug-mode-enabler
Package debug-mode-enabler
Short Description Debug mode enabler - safe and clean way to manage Debug Mode in your App
License MIT
Homepage https://github.com/redbitcz/php-debug-mode-enabler
Informations about the package debug-mode-enabler
PHP Debug Mode Enabler
Safe and clean way to manage Debug Mode in your app by specific environment and/or manually in App. Package automatically detects development environments and provide secure way to temporary switch Debug Mode of your App at any environment.
Features
Package allows your app to switch to Debug Mode:
- automatically on localhost's environment by IP,
- semi-automatically on any environment where you set
APP_DEBUG
environment variable (useful for Docker dev-stack), - semi-automatically disable Debug mode on any environment where you set
app-debug-mode
cookie variable (useful for tests and similar cases), - manually enable/disable (force turn-on or turn-off) Debug Mode.
NOTE: Package does NOT provide any Debug tools directly – it only tells the app whether to switch to debug mode.
Package is optimized for invoking in very early lifecycle phase of your App
Requirements
Package requires:
- PHP version 8.0, 8.1, 8.2, 8.3 or 8.4
Enabler requires:
- Temporary directory with writable access
SignUrl plugin requires:
- Firebase JWT v5 or v6
Installation
Using
Anywhere in your app you can determine if app is running in Debug mode by simple code:
It returns $debugMode
= true
when it detects Debug environment or manually switched.
Using with Nette
In Boostrap use package like in this example:
I know, you love DI Container to build services like this. But Container Loader need to know Debug Mode state before is DI Container ready, you cannot use DI for Debug Mode detecting.
Using with Docker
If you are building custom Docker image for your devstack, add the environment variable APP_DEBUG=1
. For example in Dockerfile
file:
Avoid to publish these image to production!
Using with Docker compose
In your devstack set environment variable APP_DEBUG=1
. For example in docker-compose.yml
file:
Manually switch
WARNING – DANGER ZONE: Following feature allows you to force Debug Mode on any environment, including production. Please use it with great caution only! Wrong use might cause critical security issue! Before using Enabler's feature, make sure your app is resistant to XSS, CSRF and similar attacks!
Enabler provide feature to force enable or disable Debug Mode anywhere for user's browser (drived by Cookie).
This example turn on Debug Mode for user's browser:
Options
$enabler->activate(true)
- force to Debug Mode turn on,$enabler->activate(false)
- force to Debug Mode turn off,$enabler->deactivate()
- reset back to automatically detection by environment.
Using with Nette
Debug Mode Enabler (unlike Debug Mode Detector) can be simply served through DI Container with configuration in config.neon
:
At most cases this example creates second instance of Enabler
class because first one is already created
internally with Detector
instance in Bootstrap
.
To re-use already existing instance you can inject it to DI Container:
Don't forget letting know DI Container with service declaration in config.neon
:
Plugins
Detector supports custom plugin. You can build custom plugin to provide your own roles to manage Debug Mode. Plugin must
implements Plugin
interface what means add __invoke()
method. That method is called always is Detector aksed to
detect mode.
Plugin retuns result of detection:
null
– no result – Detector will try to ask another plugin or detection method to decidetrue
– force turn-on debug mode for current requestfalse
– force turn-off debug mode for current request
Note: You should return null
value when Plugin doesn't explicitly matches rule. Boolean value is always stops
processing detection rules.
Don't do this:
instead return null
when your rule is not matched:
Your Plugin you can register to Detector with method appendPlugin()
or prepedndPlugin()
.
SignUrl plugin
SignUrl
plugin provide secure way to share link with activated Debug Mode.
Security notes
Wrong usage of the SignUrl
plugin can open critical vulnerability issue at your App. Follow this instructions:
- Always create
SignUrl
with strong and Secret key, use key generator like:base64_encode(random_bytes(32))
- Always create
SignUrl
with specified$audience
parameter which distinguishes versions of app (stage vs production) to prevent unwanted re-using signatures between them (read more about importance of audience).
License
The MIT License (MIT). Please see License File for more information.