InvalidConfigurationException with new schema validation

9 months ago

prog
Backer | 1
+
0
-

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)

10 days ago

xr
Member | 82
+
0
-

I have just stumbled upon this and wonder myself…

How did you solve this issue?

10 days ago

Mabar
Member | 201
+
0
-

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();

10 days ago

David Grudl
Nette Core | 6928
+
0
-

Hmmm, related to https://github.com/…i/issues/221

Probably I'll revert it.

10 days ago

xr
Member | 82
+
0
-

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.

10 days ago

Mabar
Member | 201
+
0
-

@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?

10 days ago

xr
Member | 82
+
0
-

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%
?>

10 days ago

xr
Member | 82
+
0
-

FYI: I'm getting the same issue with nette/di 3.0.0, 3.0.1 and 3.0.2.

10 days ago

Mabar
Member | 201
+
0
-

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

10 days ago

David Grudl
Nette Core | 6928
+
+1
-

Fixed