SMSM
SMSM

Reputation: 1529

Generate parameters.yml from environment variable using array node with env-map option in Composer.json - incenteev-parameters

I have this parameters file structure in a symfony 3.2 console application

parameters:
    database:
        driver: pdo_mysql
        host: 127.0.0.1
        dbname: dbname
        user: 123
        password: 123
    log_path: /logs

I use composer.json to create parameters.yml from environment variable:

        "incenteev-parameters": [
        {
            "file": "app/config/parameters.yml",
            "env-map": {

                "driver: "_DB_DRIVER",
                "host": "_DB_HOST",
                "name": "_DB_NAME",
                "user": "_DB_USER",
                "password": "_DB_PASSWORD",
                "log_path" : "-LPATH"
            }
        },
        {
            "file": "app/config/parameters.yml",
            "dist-file": "app/config/parameters.yml.dist",
            "parameter-key": "parameters"
        }
    ]

Why do the values under database node not update, when I run the following command?

_DB_HOST=“SOMEVALUE”  composer install  -n

Also why the env() function not work in , ex :

 "user": "%env(user)%",

Upvotes: 1

Views: 2216

Answers (1)

flyx
flyx

Reputation: 39738

Handling nested parameters is not implemented. See

https://github.com/Incenteev/ParameterHandler/issues/35#issuecomment-64426645

(very similar to your problem) and

https://github.com/Incenteev/ParameterHandler/pull/54

(which seems to fix the problem – although it is not very clear if this also implements replacing nested parameters via env variables).

For reference, the solution suggested in the first link applied to your situation is

parameters:
  db_driver: pdo_mysql
  db_host: 127.0.0.1
  db_name: dbname
  db_user: 123
  db_password: 123
  log_path: /logs

And then in composer.json:

...
"env-map": {
  "db_driver: "_DB_DRIVER",
  "db_host": "_DB_HOST",
  ...
}
...

Upvotes: 2

Related Questions