| 148 |
lars |
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 |
if ('cli' !== PHP_SAPI) {
|
|
|
14 |
throw new Exception('This script must be run from the command line.');
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Starts a dump server to collect and output dumps on a single place with multiple formats support.
|
|
|
19 |
*
|
|
|
20 |
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
use Psr\Log\LoggerInterface;
|
|
|
24 |
use Symfony\Component\Console\Application;
|
|
|
25 |
use Symfony\Component\Console\Input\ArgvInput;
|
|
|
26 |
use Symfony\Component\Console\Input\InputOption;
|
|
|
27 |
use Symfony\Component\Console\Logger\ConsoleLogger;
|
|
|
28 |
use Symfony\Component\Console\Output\ConsoleOutput;
|
|
|
29 |
use Symfony\Component\VarDumper\Command\ServerDumpCommand;
|
|
|
30 |
use Symfony\Component\VarDumper\Server\DumpServer;
|
|
|
31 |
|
|
|
32 |
function includeIfExists(string $file): bool
|
|
|
33 |
{
|
|
|
34 |
return file_exists($file) && include $file;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
if (
|
|
|
38 |
!includeIfExists(__DIR__ . '/../../../../autoload.php') &&
|
|
|
39 |
!includeIfExists(__DIR__ . '/../../vendor/autoload.php') &&
|
|
|
40 |
!includeIfExists(__DIR__ . '/../../../../../../vendor/autoload.php')
|
|
|
41 |
) {
|
|
|
42 |
fwrite(STDERR, 'Install dependencies using Composer.'.PHP_EOL);
|
|
|
43 |
exit(1);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
if (!class_exists(Application::class)) {
|
|
|
47 |
fwrite(STDERR, 'You need the "symfony/console" component in order to run the VarDumper server.'.PHP_EOL);
|
|
|
48 |
exit(1);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
$input = new ArgvInput();
|
|
|
52 |
$output = new ConsoleOutput();
|
|
|
53 |
$defaultHost = '127.0.0.1:9912';
|
|
|
54 |
$host = $input->getParameterOption(['--host'], $_SERVER['VAR_DUMPER_SERVER'] ?? $defaultHost, true);
|
|
|
55 |
$logger = interface_exists(LoggerInterface::class) ? new ConsoleLogger($output->getErrorOutput()) : null;
|
|
|
56 |
|
|
|
57 |
$app = new Application();
|
|
|
58 |
|
|
|
59 |
$app->getDefinition()->addOption(
|
|
|
60 |
new InputOption('--host', null, InputOption::VALUE_REQUIRED, 'The address the server should listen to', $defaultHost)
|
|
|
61 |
);
|
|
|
62 |
|
|
|
63 |
$app->add($command = new ServerDumpCommand(new DumpServer($host, $logger)))
|
|
|
64 |
->getApplication()
|
|
|
65 |
->setDefaultCommand($command->getName(), true)
|
|
|
66 |
->run($input, $output)
|
|
|
67 |
;
|