Skip to content

[VarDumper] Provide binary, allowing to start a server at any time #26654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/Symfony/Component/VarDumper/Resources/bin/var-dump-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env php
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Starts a dump server to collect and output dumps on a single place with multiple formats support.
*
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/

use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\VarDumper\Command\ServerDumpCommand;
use Symfony\Component\VarDumper\Server\DumpServer;

function includeIfExists(string $file): bool
{
return file_exists($file) && include $file;
}

if (
!includeIfExists(__DIR__ . '/../../../../autoload.php') &&
!includeIfExists(__DIR__ . '/../../vendor/autoload.php') &&
!includeIfExists(__DIR__ . '/../../../../../../vendor/autoload.php')
) {
fwrite(STDERR, 'Install dependencies using Composer.'.PHP_EOL);
exit(1);
}

if (!class_exists(Application::class)) {
fwrite(STDERR, 'You need the "symfony/console" component in order to run the VarDumper server.'.PHP_EOL);
exit(1);
}

$input = new ArgvInput();
$output = new ConsoleOutput();
$defaultHost = '127.0.0.1:9912';
$host = $input->getParameterOption(['--host'], $_SERVER['VAR_DUMPER_SERVER'] ?? $defaultHost, true);
$logger = interface_exists(LoggerInterface::class) ? new ConsoleLogger($output->getErrorOutput()) : null;

$app = new Application();

$app->getDefinition()->addOption(
new InputOption('--host', null, InputOption::VALUE_REQUIRED, 'The address the server should listen to', $defaultHost)
);

$app->add($command = new ServerDumpCommand(new DumpServer($host, $logger)))
->getApplication()
->setDefaultCommand($command->getName(), true)
->run($input, $output)
;
5 changes: 4 additions & 1 deletion src/Symfony/Component/VarDumper/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"suggest": {
"ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).",
"ext-intl": "To show region name in time zone dump",
"symfony/console": "To use the ServerDumpCommand"
"symfony/console": "To use the ServerDumpCommand and/or the bin/var-dump-server script"
},
"autoload": {
"files": [ "Resources/functions/dump.php" ],
Expand All @@ -41,6 +41,9 @@
"/Tests/"
]
},
"bin": [
"Resources/bin/var-dump-server"
],
"minimum-stability": "dev",
"extra": {
"branch-alias": {
Expand Down