dump_destination in symfony/debug-bundle config

ε祈祈猫儿з 提交于 2021-01-29 12:28:54

问题


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.

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 .

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 ?

SOLUTION

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

.env

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

Kernel.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 is required after every DUMP_SERVER variable change in .env file.


回答1:


Another ideas how to solve this problem:

  • 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.


来源:https://stackoverflow.com/questions/51734687/dump-destination-in-symfony-debug-bundle-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!