php - Using the resolve operator in the Symfony config env() helper
This article introduces type-casting and some convenient operators which can be used inside theenv()
helper in the Symfony configs. Everything's clear except theresolve:
operator. The article says:
The resolve: operator replaces container parameter names by their values:
What I am going to have the parameters whose names are taken from the values of the env variables? What's the point?
It's used in the doctrine bundle's config, for example:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(resolve:DATABASE_URL)%'
I was googling the issue, but it's almost no info on the Internet, and it doesn't clarify anything to me.
Answer
Solution:
It's pretty simple. In your example you have:
If DATABASE_URL value itself contains any container parameters, like Romain example:
Since DATABASE_URL contains %kernel.project_dir% parameter, which would be the root directory of your project.
By using resolve, you make this %kernel.project_dir% parameter being replaced by it's value.
Without resolve url will be:
With resolve (an example) url will be:
Answer
Solution:
What's the actual value of
DATABASE_URL
and what's the expected result ?Example from documentation: