ENV processing / type casting

Since we add more and more type hints (good) some cases emerge where we have information incoming that might have been casted automatically before that will result in an error, eg. from Settings. My special case / problem here is Settings via environment variables.

Take our elastic search client configuration for example:

Flowpack:
  ElasticSearch:
    clients:
      default:
        -
          host: localhost
          port: 9200

If I were to configure this via env variables (eg. the port line would look like this port: '%env:ELASTICSEARCH_PORT%' ) I have a problem these days as the environment variable is a string and the port option now has a type hint. Before the type hints it would just work by implicit casting along the way, but now there is no way to configure that via environment variables anymore.

Symfony has this: https://symfony.com/doc/current/configuration/env_var_processors.html
And it seems to me we will need something similar to allow casting configuration values from environment variables. Not sure if we have other places were we need to watch out for problems with type hints as well.

Any other ideas? Sadly the symfony code is not standalone but at least could be used as inspiration for our own implementation. What do you think?

1 Like

Note the symfony processors can do a lot, but for now I would limit ourselves to bool, int, string, json, those seem straight forward and easy to implement…

1 Like

I’d give it a go and use the same syntax Symfony does. And then let’s go the full route and implement custom processors right away – shouldn’t be that big additional work, right?