xfloys2112
xfloys2112

Reputation: 695

Symfony2 default configuration parameters

Is it possible to have a default configuration parameters in Symfony yeml configuration file. In case where the variable parameter is not available. For example. I have database name coming from Apache configuration, but if I run a command I would like to go with a default database, see below. The example is kind of twigi'ish

doctrine:
dbal:
    driver:   pdo_mysql
    host:     "%database_host%"
    port:     "%database_port%"
    dbname:   "%database.name%"|default('database1')
    user:     "%database_user%"
    password: "%database_password%"

Upvotes: 2

Views: 92

Answers (3)

xfloys2112
xfloys2112

Reputation: 695

I figured out a way around this problem by using "database_prefix" as the default database and other databases just add a suffix to that.

doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "database_prefix%database.name%"
        user:     "%database_user%"
        password: "%database_password%"

Upvotes: 0

Gerry
Gerry

Reputation: 6012

The only way to do that would be to set the parameter to a default value, which I assume would be early in the configuration file. A theoretic example:

parameters:
    foo: bar

imports:
    - { resource: parameters.yml }

If parameters.yml contains a definition for the %foo% parameter, it will overwrite the previous definition. If parameter.yml does not contain a definition for %foo% however, it will use the earlier defined (default) value.

Upvotes: 1

Youssef
Youssef

Reputation: 1043

You can put your default configuration in parameters.yml.dist, this way when someone new joins the project and runs:

composer install

or

composer update

He will be prompted to provide his environment specific values and so parameters.yml will be created.

Upvotes: 0

Related Questions