0
votes

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

1 Answers

1
votes

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.