使用自定义值时,composer update会覆盖parameters.yml

时间:2015-02-18 02:21:52

标签: symfony composer-php

我在parameters.yml中有一些自定义条目,每次运行作曲家更新时,它都想添加缺少的条目,这甚至会覆盖我的自定义条目。我怎么能阻止这个?

e.g。在作曲家更新之前

#parameters.yml
# Env = GLOBAL
parameters:
# DB settings - GLOBAL
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: 3306

#mailer settings
mailer_to: yo@yo.com
mailer_from: yo@site.com
mailer_transport: smtp
mailer_subject: ":-| Something is broken!"

# Framework use - GLOBAL
locale: en

#parameters.yml
# This file is auto-generated during the composer install
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: 3306
mailer_transport: smtp
locale: en
database_name: 
database_user: 
database_password: 
mailer_host: 
mailer_user: 
mailer_password: 
secret: 

幸运的是我的repo和我的工作文件通过我的ide是两个不同的文件,需要同步。在我运行编辑器更新后,当我运行同步时,我将所有文件下载到我的IDE除了参数.yml,我推回去覆盖刚刚自动创建的那个。

我想消除这个麻烦,因为我将db密码保存在per / env文件中。

编辑:当我尝试将不需要的变量作为虚拟值填充时,将它们归零,它也会发生逆火。

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Generating autoload files
Updating the "app/config/parameters.yml" file
Some parameters are missing. Please provide them.
database_name: null
database_user: null
database_password: null
mailer_host: null
mailer_user: null
mailer_password: null
secret: null

  [Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
  You have requested a non-existent parameter "mailer_from".

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception

  [RuntimeException]
  An error occurred when executing the "'cache:clear --no-warmup'" command.

自定义参数本身也会导致问题。

所以现在我去看看我新生成的文件,看起来像这样

# This file is auto-generated during the composer install
parameters:
    database_driver: pdo_mysql
    database_host: 127.0.0.1
    database_port: 3306
    mailer_transport: smtp
    locale: en
    database_name: null
    database_user: null
    database_password: null
    mailer_host: null
    mailer_user: null
    mailer_password: null
    secret: null

但是理想的再生后我需要说的是这个

/**
* my custom comment and copyright/legal tamper warning
*/
#  Env = GLOBAL
parameters:
  # DB settings - GLOBAL
  database_driver: pdo_mysql
  database_host: 127.0.0.1
  database_port: 3306

  #mailer settings
  mail_to: me@site.com
  mail_from: site@site.com
  mail_transport: smtp
  mail_subject: ":-| Something is broken!"

  # Framework use - GLOBAL
  locale: en

我的其余参数位于另一个参数文件中,该文件根据env加载动态包含,并且每个参数文件都有不同的db信誉。

编辑 / @AlpineCoder回答: 我的最新发现为什么添加虚拟值不起作用

当我将其添加到我的parameters.yml

#dummy values  to avoid regeneration
    database_name: dummyvalue
    database_user: dummyvalue
    database_password: dummyvalue
    mailer_host: dummyvalue
    mailer_user: dummyvalue
    mailer_password: dummyvalue
    secret: dummyvalue

它不再要求我填写这些值,这很好,但是,它仍然会重新生成文件,删除所有自定义值,让我这个

# This file is auto-generated during the composer install
parameters:
    database_driver: pdo_mysql
    database_host: 127.0.0.1
    database_port: 3306
    mailer_transport: smtp
    locale: en
    database_name: dummyvalue
    database_user: dummyvalue
    database_password: dummyvalue
    mailer_host: dummyvalue
    mailer_user: dummyvalue
    mailer_password: dummyvalue
    secret: dummyvalue

2 个答案:

答案 0 :(得分:34)

你有两个选择,要么填写你的parameters.yml.dist,要么你可以去你的composer.json文件,在post-update-cmd和post-install-cmd你应该看到像

这样的东西
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",

如果删除该行,则在运行composer时将不再更改参数。

如果您正在与其他人合作,更新您的parameters.yml.dist可能是更好的方法,因为它有助于提醒他们在引入新参数时需要填写新参数。

答案 1 :(得分:5)

如果您将自定义参数(以及默认/虚拟值)添加到parameters.yml.dist文件,则不应再要求/覆盖parameters.yml文件中的自定义值。