symfony/debug-bundle 配置中的 dump_destination [英] dump_destination in symfony/debug-bundle config

查看:33
本文介绍了symfony/debug-bundle 配置中的 dump_destination的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的团队中,我们使用 SF4 并使用 .env.dist(以及 .env)作为开发人员特定的配置.当我们开发时,我们发现 symfony/var-dumper 非常有用,但是有些开发人员喜欢在浏览器中转储,有些在控制台中使用 symfony/debug-bundle 附带的 server:dump 命令转储.在从远程拉取后一遍又一遍地注释/取消注释 debug.dump_destination 键或担心当前远程 HEAD 碰巧也编辑了此文件时发生冲突是非常烦人的.

In my team we work with SF4 and use .env.dist (and so .env) for developer specific config. When we develop we find symfony/var-dumper very useful, however some devs like to dump in browser and some in console using server:dump command which comes with symfony/debug-bundle. It's very annoying to comment out / uncomment debug.dump_destination key over and over after pulling from remote or worry about conflicts when current remote HEAD happens to have this file also edited.

我尽力调试了,问题出在这里:Symfony\Bundle\DebugBundle\DependencyInjection\DebugExtension::load() 检查 0 === strpos($config['dump_destination'], 'tcp://') 和作为环境变量在构建容器之前不会解析,然后在我的 .env 文件中包含 WHATEVER="tcp://%env(VAR_DUMPER_SERVER)%"debug.dump_destination: '%env(resolve:WHATEVER)%' 导致错误(在检查 dump_destination 的那一刻是 env_93f4ff143f62ce8d_resolve_WHATEVER_e29a13ca55ef040f58272adff34dd9)作为旁注,当我不使用环境变量而只是设置 parameters.whatever: "tcp://%env(VAR_DUMPER_SERVER)%" 然后 debug.dump_destination: %whatever% 一切正常.当然,我可以创建新的 parameters.dist.yaml 文件和 parameters.yaml ,后者将被添加到 .gitignore 但我想将每个开发人员的特定信息保留在一个文件中,即 .env .

I did my best to debug this and the problem lies here: Symfony\Bundle\DebugBundle\DependencyInjection\DebugExtension::load() checks for 0 === strpos($config['dump_destination'], 'tcp://') and as environment variables are not resolved until container is built, then having, let's say, WHATEVER="tcp://%env(VAR_DUMPER_SERVER)%" in my .env file and debug.dump_destination: '%env(resolve:WHATEVER)%' leads to false (at the moment of check dump_destination is env_93f4ff143f62ce8d_resolve_WHATEVER_e29a13ca55ef040f58272adff34dd9a4) and everything brokes. As side note, when I don't use env variables but just set parameters.whatever: "tcp://%env(VAR_DUMPER_SERVER)%" and then debug.dump_destination: %whatever% everything is fine. Of course I could create new parameters.dist.yaml file and parameters.yaml where the latter would be added to .gitignore but I want to keep and have every developer specific info in one file which is .env .

总而言之,我该怎么做才能使密钥 debug.dump_destination 等于 tcp://%env(VAR_DUMPER_SERVER)% 对于一名开发人员和 null~ 为另一个?

Summarizing, what can I do to have the key debug.dump_destination equal tcp://%env(VAR_DUMPER_SERVER)% for one developer and null or ~ for another ?

按照 M. Kebza 的回答,这是我想出的解决方案:

Following M. Kebza answer this is the solution I came up with:

.env

DUMP_SERVER=null # or DUMP_SERVER=tcp://%env(VAR_DUMPER_SERVER)%

内核.php

$DUMP_SERVER = getenv('DUMP_SERVER');
if (strtolower($DUMP_SERVER) === 'null' || $DUMP_SERVER === '~') {
    $DUMP_SERVER = null;
}
$container->setParameter('DUMP_SERVER', $DUMP_SERVER);

debug.yaml

debug.dump_destination: "%DUMP_SERVER%"

bin/console cache:clear.env 文件中每次 DUMP_SERVER 变量更改后都需要.

bin/console cache:clear is required after every DUMP_SERVER variable change in .env file.

推荐答案

如何解决这个问题的另一种思路:

Another ideas how to solve this problem:

  • debug.dump_destination 设置默认值,并在每个开发人员的环境中使用 ENV 变量来设置他的首选解决方案
  • 在您的 Kernel.php 方法中的 configureContainer 检查本地文件的存在,例如 local.yaml 这可用于覆盖具体配置,这个文件在 git 中应该被忽略.
  • Have default value for debug.dump_destination and use ENV variable in environment for each developer to set his preferred solution
  • In your Kernel.php in method configureContainer check for existence of local file for example local.yaml and this can be used to override specific configurations, this file should be ignored in git.

这篇关于symfony/debug-bundle 配置中的 dump_destination的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆