I know that env variables are string only. Symfony 3.4 supports env variables type casting. Is there a way to pass null value through int validator?
.env
DATABASE_PORT=
#I also tried DATABASE_PORT=null, DATABASE_PORT=~
parameters.yml
app.connection.port: '%env(int:DATABASE_PORT)%'
#I also tried env(?int, env(int?
I'm getting an error: "Non-numeric env var "DATABASE_PORT" cannot be cast to int." or "Invalid env(?int:DATABASE_PORT) name: only "word" characters are allowed."
In yml there are ~ or null signs used to pass null, e.g:
app.connection.port: ~
Someone asked in the doc:
Is it, or will it be possible to define your own operator? Like
%env(myDecoder:API_PASSWORD)%
, which will decrypt the environment value into something usable.
class MyDecoder implements EnvironmentOperator {
public function resolve(string $value): string {
// magic stuff for decryption
return $value;
}
}
And the answer was:
yes, you just need to create a service that implements
EnvProviderInterface
and tag it withcontainer.env_provider
.
You could create an operator to accept null
as an int
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With