blob: 98c813a0639b5797bfa60d9c780860de655fcdc6 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001#!/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
19use Psr\Log\LoggerInterface;
20use Symfony\Component\Console\Application;
21use Symfony\Component\Console\Input\ArgvInput;
22use Symfony\Component\Console\Input\InputOption;
23use Symfony\Component\Console\Logger\ConsoleLogger;
24use Symfony\Component\Console\Output\ConsoleOutput;
25use Symfony\Component\VarDumper\Command\ServerDumpCommand;
26use Symfony\Component\VarDumper\Server\DumpServer;
27
28function includeIfExists(string $file): bool
29{
30 return file_exists($file) && include $file;
31}
32
33if (
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
42if (!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;