Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set the flags config via environment variable #445

Closed
zeleznypa opened this issue Nov 1, 2023 · 2 comments
Closed

Unable to set the flags config via environment variable #445

zeleznypa opened this issue Nov 1, 2023 · 2 comments

Comments

@zeleznypa
Copy link

Unfortunately, there is no possibility to setup the flags config via environment variable:

if (isset($config['flags'])) {
$flags = 0;
foreach ((array) $config['flags'] as $flag) {
$flags |= constant($flag);
}
$config['flags'] = $flags;
}

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.

@zeleznypa
Copy link
Author

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; 
 } 

@dg
Copy link
Owner

dg commented Nov 5, 2023

I tried to add the successor, DibiExtension3, can you try it?

@dg dg closed this as completed Nov 25, 2023
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

No branches or pull requests

2 participants