8000 Allow configuring host through an env var · symfony/symfony@b002175 · GitHub
[go: up one dir, main page]

Skip to content

Commit b002175

Browse files
committed
Allow configuring host through an env var
1 parent f418c8e commit b002175

File tree

6 files changed

+23
-15
lines changed

6 files changed

+23
-15
lines changed

src/Symfony/Bundle/DebugBundle/DependencyInjection/Configuration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public function getConfigTreeBuilder()
5353
->end()
5454
->arrayNode('server_dump')->canBeEnabled()
5555
->children()
56-
->scalarNode('host')->defaultValue('tcp://0.0.0.0:9912')->end()
5756
->booleanNode('swallows')
5857
->info('Swallows previously configured dumpers so dumps are output only in one place by the server')
5958
->defaultTrue()

src/Symfony/Bundle/DebugBundle/DependencyInjection/DebugExtension.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,8 @@ public function load(array $configs, ContainerBuilder $container)
5454
$serverDumperConfig = $config['server_dump'];
5555
if ($serverDumperConfig['enabled']) {
5656
$container->getDefinition(ServerDumper::class)
57-
->replaceArgument(0, $serverDumperConfig['host'])
5857
->replaceArgument(2, $serverDumperConfig['swallows'])
5958
;
60-
$container->getDefinition(ServerDumpCommand::class)
61-
->replaceArgument(2, $serverDumperConfig['host'])
62-
;
6359
} else {
6460
$container->removeDefinition(ServerDumper::class);
6561
$container->removeDefinition(ServerDumpCommand::class);

src/Symfony/Bundle/DebugBundle/Resources/config/services.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
<service id="var_dumper.cloner" class="Symfony\Component\VarDumper\Cloner\VarCloner" public="true" />
3434
<service id="Symfony\Component\VarDumper\Dumper\ServerDumper">
35-
<argument /> <!-- server host -->
35+
<argument>null</argument> <!-- server host -->
3636
<argument type="service" id="var_dumper.cli_dumper" />
3737
<argument /> <!-- whether to swallow or not wrapped dumper -->
3838
<argument type="collection">
@@ -67,7 +67,6 @@
6767
<service id="Symfony\Component\VarDumper\Command\ServerDumpCommand">
6868
<argument type="service" id="var_dumper.cli_dumper" />
6969
<argument type="service" id="var_dumper.html_dumper" />
70-
<argument/> <!-- default host -->
7170
<argument type="service" id="debug.file_link_formatter" on-invalid="null" />
7271
<argument type="string">%kernel.project_dir%</argument>
7372
<argument type="service" id="logger" on-invalid="null" />

src/Symfony/Component/VarDumper/Command/ServerDumpCommand.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,16 @@ class ServerDumpCommand extends Command
114114

115115
private $cliDumper;
116116
private $htmlDumper;
117-
private $defaultHost;
118117
private $fileLinkFormatter;
119118
private $projectDir;
120119
private $logger;
121120
/** @var Filesystem */
122121
private $filesystem;
123122

124-
public function __construct(CliDumper $cliDumper = null, HtmlDumper $htmlDumper = null, $defaultHost = 'tcp://0.0.0.0:9912', FileLinkFormatter $fileLinkFormatter, $projectDir = null, LoggerInterface $logger = null)
123+
public function __construct(CliDumper $cliDumper = null, HtmlDumper $htmlDumper = null, FileLinkFormatter $fileLinkFormatter, $projectDir = null, LoggerInterface $logger = null)
125124
{
126125
$this->cliDumper = $cliDumper;
127126
$this->htmlDumper = $htmlDumper;
128-
$this->defaultHost = $defaultHost;
129127
$this->fileLinkFormatter = $fileLinkFormatter;
130128
$this->projectDir = $projectDir;
131129
$this->logger = $logger;
@@ -137,7 +135,6 @@ protected function configure()
137135
{
138136
$this
139137
->setName('server:dump')
140-
->addOption('host', null, InputOption::VALUE_REQUIRED, 'The server host', $this->defaultHost)
141138
->addOption('output', null, InputOption::VALUE_REQUIRED, 6D4E 'An file path to save dumped data in html format, or null to display on CLI output.')
142139
->setDescription('Starts a dump server that collects and displays dumps in a single place')
143140
->setHelp(<<<'EOF'
@@ -161,7 +158,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
161158

162159
$io->title('Symfony Var Dumper Server');
163160

164-
$server = new DumpServer($input->getOption('host'), $this->logger);
161+
$server = new DumpServer(null, $this->logger);
165162

166163
$server->start();
167164

src/Symfony/Component/VarDumper/Dumper/ServerDumper.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\VarDumper\Dumper;
1313

1414
use Symfony\Component\VarDumper\Cloner\Data;
15+
use Symfony\Component\VarDumper\Server\DumpServer;
1516

1617
/**
1718
* ServerDumper forwards serialized Data clones to a server.
@@ -27,15 +28,20 @@ class ServerDumper implements DataDumperInterface
2728
private $contextProviders;
2829

2930
/**
30-
* @param string $host
31+
* @param string|null $host The server host or null to read it from the VAR_DUMPER_SERVER
32+
* env var
3133
* @param DataDumperInterface|null $wrappedDumper A wrapped instance used whenever we failed contacting the
3234
* server, or if swallows is false
3335
* @param bool $swallows Whether to use or not the wrapped dumper instance on normal
3436
* use
3537
* @param callable[] $contextProviders Callables indexed by name returning a context array
3638
*/
37-
public function __construct($host, DataDumperInterface $wrappedDumper = null, $swallows = true, array $contextProviders = array())
39+
public function __construct($host = null, DataDumperInterface $wrappedDumper = null, $swallows = true, array $contextProviders = array())
3840
{
41+
if (null === $host) {
42+
$host = getenv(DumpServer::HOST_ENV_VAR) ?: DumpServer::DEFAULT_HOST;
43+
}
44+
3945
if (false === strpos($host, '://')) {
4046
$host = 'tcp://'.$host;
4147
}

src/Symfony/Component/VarDumper/Server/DumpServer.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,23 @@
2121
*/
2222
class DumpServer
2323
{
24+
const HOST_ENV_VAR = 'VAR_DUMPER_SERVER';
25+
const DEFAULT_HOST = 'tcp://0.0.0.0:9912';
26+
2427
private $host;
2528
private $socket;
2629
private $logger;
2730

28-
public function __construct($host, LoggerInterface $logger = null)
31+
/**
32+
* @param string|null $host The server host or null to read it from the VAR_DUMPER_SERVER env var
33+
* @param LoggerInterface|null $logger
34+
*/
35+
public function __construct($host = null, LoggerInterface $logger = null)
2936
{
37+
if (null === $host) {
38+
$host = getenv(static::HOST_ENV_VAR) ?: static::DEFAULT_HOST;
39+
}
40+
3041
if (false === strpos($host, '://')) {
3142
$host = 'tcp://'.$host;
3243
}

0 commit comments

Comments
 (0)
0