gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:16:18 25 4
gpt4 key购买 nike

我的parameters.yml中有一些自定义条目,每次我运行composer更新时,它都会添加缺少的条目,这更糟糕的是会覆盖我的自定义条目。我怎样才能阻止这个?

例如 Composer 更新之前

#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:

幸运的是,我的存储库和 ide 中的工作文件是两个不同的文件,需要同步。在我运行 Composer Update 后,当我运行同步时,我会将所有文件下载到我的 IDE,除了parameters.yml,我将其推回以覆盖刚刚自动创建的文件。

我想消除这个麻烦,因为我将数据库密码保存在 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 加载的内容动态包含,并且每个参数都有不同的数据库信用。

编辑 根据 @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

最佳答案

您有两个选择,要么填写您的parameters.yml.dist,要么您可以转到您的composer.json文件,在post-update-cmd和post-install-cmd中您应该看到类似的内容

"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",

如果删除该行,当您运行 Composer 时,您的参数将不再更改。

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

关于symfony - 使用自定义值时,composer update 会不断覆盖parameters.yml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28574912/

25 4 0