InvalidConfigurationException with new schema validation
- prog
- Backer | 1
This is how I configure app with environment vars:
parameters:
db:
dsn: ::getenv('APP_DB_DSN')
user: ::getenv('APP_DB_USER')
...
database:
default:
dsn: %db.dsn%
user: %db.user%
...
Since new schema validation I am getting
Nette\DI\InvalidConfigurationException
The option 'database › default › dsn' expects to be string or Nette\Schema\DynamicParameter, object Nette\DI\Definitions\Statement given.
Any ideas how to solve this use case?
Last edited by prog (2019-04-10 12:41)
- Marek Bartoš
- Nette Blogger | 1261
We load env variables into parameters through Configurator. You can use e.g. contributte/bootstrap for that
use Contributte\Bootstrap\ExtraConfigurator;
$configurator = new ExtraConfigurator();
$configurator->addEnvParameters();
- David Grudl
- Nette Core | 8218
Hmmm, related to https://github.com/…i/issues/221
Probably I'll revert it.
- xr
- Member | 94
I filed an issue here as well – was not sure if this thread was stale or
not.
https://github.com/…i/issues/228
Thanks for your response. I'll check v 3.0.1 if the issue is present
or not.
- Marek Bartoš
- Nette Blogger | 1261
@DavidGrudl Problem will be probably also with that none of our extensions accepts Statement (except options accepting services), all Contributte extensions expect final values. Can we somehow find out what will final values get from Statement be?
- xr
- Member | 94
I checked the contributte “ExtraConfigurator”… It does not solve my case, because prefixing ENV vars is not an option (on servers, renaming them would be a BC break for older projects and duplicationg would bring maintenance hell).
Similarly, I could write a tool that would load variables in similar manner or create DynamicParameters out of desired ENV vars, but this is still sub optimal for something as simple as this.
I'm guessing that something like the following would not work either, would it?
<?php
// neon
parameters:
system:
proxy: @envWrapper::getEnvAsDynamicParameter(TRUSTED_PROXIES)
http:
proxy: %system.proxy%
?>
- Marek Bartoš
- Nette Blogger | 1261
Feel free to copy my implementation then. I am not sure if empty prefix will
work, but it should not be hard modify it to not use prefix at all.
https://github.com/…ntHelper.php
- matoni555
- Member | 40
I use nette/di v3.0.5 and I still get Nette\DI\InvalidConfigurationException (The option ‘gosms › clientId’ expects to be string, object Nette\DI\Definitions\Statement given.) with this:
gosms:
clientId: @settings::getGoSmsClientId()
clientSecret: 123456789
services:
settings:
class: Settings
Any suggestion how to solve it?