Unable to set the `flags` config via environment variable
zeleznypa opened this issue · comments
Pavel Železný commented
Unfortunately, there is no possibility to setup the flags
config via environment variable:
dibi/src/Dibi/Bridges/Nette/DibiExtension22.php
Lines 50 to 57 in 9e71132
When I have a neon config like this:
extensions:
dibi: Dibi\Bridges\Nette\DibiExtension22
dibi:
host: Utils\Extras::getenv('DATABASE_HOST')
port: Utils\Extras::getenv('DATABASE_PORT', 3306)
username: Utils\Extras::getenv('DATABASE_USER')
password: Utils\Extras::getenv('DATABASE_PASSWORD')
database: Utils\Extras::getenv('DATABASE_NAME')
charset: Utils\Extras::getenv('DATABASE_CHARSET', 'utf8')
flags: Utils\Extras::getenv('DATABASE_FLAGS', 0)
lazy: Utils\Extras::getenv('DATABASE_LAZY', true)
The marked code tried to interpret the Nette\DI\Definitions\Statement
as an array and it leads to wrong code.
Pavel Železný commented
Probably the right solution can be:
if (isset($config['flags']) && (is_array($config['flags']) || is_scalar($config['flags']))) {
$flags = 0;
foreach ((array) $config['flags'] as $flag) {
$flags |= constant($flag);
}
$config['flags'] = $flags;
}
or similar one:
if (isset($config['flags']) && !is_object($config['flags']) {
$flags = 0;
foreach ((array) $config['flags'] as $flag) {
$flags |= constant($flag);
}
$config['flags'] = $flags;
}
David Grudl commented
I tried to add the successor, DibiExtension3, can you try it?