Set config debug mode into neon config

Sitole
Member | 39
+
0
-

Hello there,
I looking for easy and developer friendly set debug mode into NEON configure file, becose i use two different configure files. “config.neon” with product application settings and “config.local.neon” with confugre only for local development. Now i must change configuration of method $configurator->setDebugMode(true); inside boostrap.php on false. How convert this method function into NEON configure file?

Last edited by Sitole (2017-12-10 12:01)

Felix
Nette Core | 1189
+
+4
-

Hi,

well you can't because Nette setup debug mode before neon files are loaded (https://api.nette.org/…tor.php.html#…).

I think you can achieve it other ways.


1. Detect by file

Let's choose some file, for example root/app/.debug with no content and update your bootstrap.php.

if (file_exists(__DIR__ . '/.debug')) {
    $configurator->setDebugMode(TRUE);
}

You will be absolute free of change of bootstrap.php.

2. Detect by file content

You can extend Nette\Configurator and add method setDebugModeBy(file).

Inside your new Configurator.

public function setDebugModeBy($file)
{
    $loader = new Nette\DI\Config\Loader();
    $content = $loader->load($file);

    if (isset($content['mode'])) {
        $this->setDebugMode($content['mode']);
    }
}

It's more powerful, you can override more parameters/settings.

3. Detect by ENV

if (getenv('NETTE_DEBUG', true)) == '1') {
    $configurator->setDebugMode(TRUE);
}

Be aware of 3rd party change.

Last edited by Felix (2017-12-17 21:58)