This article introduces type-casting and some convenient operators which can be used inside the env()
helper in the Symfony configs. Everything's clear except the resolve:
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.
It's pretty simple. In your example you have:
url: '%env(resolve:DATABASE_URL)%'
If DATABASE_URL value itself contains any container parameters, like Romain example:
parameters:
env(DATABASE_URL): 'sqlite://%kernel.project_dir%/var/data.db'
db_dsn: '%env(resolve:DB)%'
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:
url: 'sqlite://%kernel.project_dir%/var/data.db'
With resolve (an example) url will be:
url: 'sqlite:///Users/your_name/whatever/directory/var/data.db'
What's the actual value of DATABASE_URL
and what's the expected result ?
Example from documentation:
parameters:
project_dir: '/foo/bar'
env(DB): 'sqlite://%%project_dir%%/var/data.db'
db_dsn: '%env(resolve:DB)%'