|
| 1 | +# PHP Debug Mode Enabler |
| 2 | +> not only for Nette Tracy Debugger |
| 3 | +
|
| 4 | +Safe and clean way to manage Debug Mode in your app by specific environment and/or manually in app. |
| 5 | +Package provide secure way to temporary switch Debug Mode of your App at any environment. |
| 6 | + |
| 7 | +## Features |
| 8 | +Package allows your app to switch to Debug Mode: |
| 9 | +- automatically on localhost's environment by IP, |
| 10 | +- semi-automatically on any envirovnemnt where you set `PHP_APP_DEBUG_MODE` environment variable (useful for Docker dev-stack), |
| 11 | +- allows you to switch (force turn-on or turn-off) Debug Mode manually. |
| 12 | + |
| 13 | +> NOTE: Package is NOT provide any Debug tools directly – it only gives the app whether to switch to debug mode. |
| 14 | +
|
| 15 | +## Installation |
| 16 | +```bash |
| 17 | +composer require redbitcz/debug-mode-enabler |
| 18 | +``` |
| 19 | + |
| 20 | +## Requirements |
| 21 | +Package is require PHP <=7.3 and temporary directory with writable access. |
| 22 | + |
| 23 | +## Using |
| 24 | +Anywhere in your app you can determine if app is running in Debug mode by simple code: |
| 25 | +```php |
| 26 | +$detector = new \Redbitcz\DebugMode\DebugModeDetector($tempDir); |
| 27 | +$debugMode = $detector->isDebugMode(); // boolean |
| 28 | +``` |
| 29 | +where `$tempDir` is required absolute path to temporary directory. |
| 30 | + |
| 31 | +It returns `$debudMode` = `true` when is detected Debug environment or manually switched. |
| 32 | + |
| 33 | +### Using with Nette |
| 34 | + |
| 35 | +In `\App\Bootstrap` class use package like this example: |
| 36 | +```php |
| 37 | +$tempDir = __DIR__ . '/../temp'; |
| 38 | +$debugModeDetector = new \Redbitcz\DebugMode\DebugModeDetector($tempDir); |
| 39 | + |
| 40 | +$configurator = new Configurator(); |
| 41 | +$configurator->setDebugMode($debugModeDetector->isDebugMode()); |
| 42 | +``` |
| 43 | +> I know, you love DI Container to build services like this. But Container Loader need to know Debug Mode state before is |
| 44 | +> DI Container ready, you cannot use DI for Debug Mode detecting. |
| 45 | +
|
| 46 | +## Using with Docker |
| 47 | +If you building custom Docker image for your devstack, add the environment variable `PHP_APP_DEBUG_MODE=1`. For example in `Dockerfile` file: |
| 48 | +``` |
| 49 | +ENV PHP_APP_DEBUG_MODE 1 |
| 50 | +``` |
| 51 | +> Avoid to publish these image to production! |
| 52 | +
|
| 53 | +## Using with Docker compose |
| 54 | +In your devstack set environment variable `PHP_APP_DEBUG_MODE=1`. For example in `docker-compose.yml` file: |
| 55 | +```yaml |
| 56 | +environment: |
| 57 | + PHP_APP_DEBUG_MODE: 1 |
| 58 | +``` |
| 59 | +
|
| 60 | +## Manually switch |
| 61 | +<p align="center"> |
| 62 | + <img width="368" height="280" src="https://user-images.githubusercontent.com/1657322/78752208-f2354a00-7973-11ea-83ea-b2719e326dc8.png"> |
| 63 | +</p> |
| 64 | +
|
| 65 | +**WARNING – DANGER ZONE:** Following feature allows to force Debug Mode on any environment, production including. |
| 66 | +Please use it with great caution only! Wrong use might cause to critical security issue! Before using Enabler's feature be |
| 67 | +aware your app is resistant to XSS, CSRF and similar attacks! |
| 68 | +
|
| 69 | +Enabler provide feature to force enable or disable Debug Mode anywhere for user's browser (drived by Cookie). |
| 70 | +
|
| 71 | +This example turn on Debug Mode for user's browser: |
| 72 | +```php |
| 73 | +$enabler = new \Redbitcz\DebugMode\DebugModeEnabler($tempDir); |
| 74 | +$enabler->activate(true); |
| 75 | +``` |
| 76 | + |
| 77 | +### Options |
| 78 | +- `$enabler->activate(true)` - force to Debug Mode turn on, |
| 79 | +- `$enabler->activate(false)` - force to Debug Mode turn off, |
| 80 | +- `$enabler->deactivate(false)` - reset back to automatically detection by environment. |
| 81 | + |
| 82 | +License |
| 83 | +------- |
| 84 | +The MIT License (MIT) |
| 85 | + |
| 86 | +Copyright (c) 2020 Redbit s.r.o., Jakub Bouček |
| 87 | + |
| 88 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 89 | +of this software and associated documentation files (the "Software"), to deal |
| 90 | +in the Software without restriction, including without limitation the rights |
| 91 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 92 | +copies of the Software, and to permit persons to whom the Software is |
| 93 | +furnished to do so, subject to the following conditions: |
| 94 | + |
| 95 | +The above copyright notice and this permission notice shall be included in all |
| 96 | +copies or substantial portions of the Software. |
| 97 | + |
| 98 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 99 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 100 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 101 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 102 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 103 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 104 | +SOFTWARE. |
0 commit comments