10000 feature #26654 [VarDumper] Provide binary, allowing to start a server… · symfony/symfony@be1b55b · GitHub
[go: up one dir, main page]

Skip to content

Commit be1b55b

Browse files
committed
feature #26654 [VarDumper] Provide binary, allowing to start a server at any time (ogizanagi)
This PR was merged into the 4.1-dev branch. Discussion ---------- [VarDumper] Provide binary, allowing to start a server at any time as soon as the "symfony/var-dumper" & "symfony/console" components are available. | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | N/A <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | TODO symfony/symfony-docs#9474 Now that #23831 is merged, there is still room for improvements we can bring during the stabilization months. Here is a first one: providing a simple CLI binary allows to easily start a server from any project (or even globally), just by having the var dumper & console packages in your deps. Commits ------- eef10b1 [VarDumper] Provide binary, allowing to start a server at any time
2 parents 9dd89e0 + eef10b1 commit be1b55b

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
* This file is part of the Symfony package.
6+
*
7+
* (c) Fabien Potencier <fabien@symfony.com>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
/**
14+
* Starts a dump server to collect and output dumps on a single place with multiple formats support.
15+
*
16+
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
17+
*/
18+
19+
use Psr\Log\LoggerInterface;
20+
use Symfony\Component\Console\Application;
21+
use Symfony\Component\Console\Input\ArgvInput;
22+
use Symfony\Component\Console\Input\InputOption;
23+
use Symfony\Component\Console\Logger\ConsoleLogger;
24+
use Symfony\Component\Console\Output\ConsoleOutput;
25+
use Symfony\Component\VarDumper\Command\ServerDumpCommand;
26+
use Symfony\Component\VarDumper\Server\DumpServer;
27+
28+
function includeIfExists(string $file): bool
29+
{
30+
return file_exists($file) && include $file;
31+
}
32+
33+
if (
34+
!includeIfExists(__DIR__ . '/../../../../autoload.php') &&
35+
!includeIfExists(__DIR__ . '/../../vendor/autoload.php') &&
36+
!includeIfExists(__DIR__ . '/../../../../../../vendor/autoload.php')
37+
) {
38+
fwrite(STDERR, 'Install dependencies using Composer.'.PHP_EOL);
39+
exit(1);
40+
}
41+
42+
if (!class_exists(Application::class)) {
43+
fwrite(STDERR, 'You need the "symfony/console" component in order to run the VarDumper server.'.PHP_EOL);
44+
exit(1);
45+
}
46+
47+
$input = new ArgvInput();
48+
$output = new ConsoleOutput();
49+
$defaultHost = '127.0.0.1:9912';
50+
$host = $input->getParameterOption(['--host'], $_SERVER['VAR_DUMPER_SERVER'] ?? $defaultHost, true);
51+
$logger = interface_exists(LoggerInterface::class) ? new ConsoleLogger($output->getErrorOutput()) : null;
52+
53+
$app = new Application();
54+
55+
$app->getDefinition()->addOption(
56+
new InputOption('--host', null, InputOption::VALUE_REQUIRED, 'The address the server should listen to', $defaultHost)
57+
);
58+
59+
$app->add($command = new ServerDumpCommand(new DumpServer($host, $logger)))
60+
->getApplication()
61+
->setDefaultCommand($command->getName(), true)
62+
->run($input, $output)
63+
;

src/Symfony/Component/VarDumper/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"suggest": {
3333
"ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).",
3434
"ext-intl": "To show region name in time zone dump",
35-
"symfony/console": "To use the ServerDumpCommand"
35+
"symfony/console": "To use the ServerDumpCommand and/or the bin/var-dump-server script"
3636
},
3737
"autoload": {
3838
"files": [ "Resources/functions/dump.php" ],
@@ -41,6 +41,9 @@
4141
"/Tests/"
4242
]
4343
},
44+
"bin": [
45+
"Resources/bin/var-dump-server"
46+
],
4447
"minimum-stability": "dev",
4548
"extra": {
4649
"branch-alias": {

0 commit comments

Comments
 (0)
0