You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.1 KiB

2 years ago
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * This file is part of the Symfony package.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. if ('cli' !== PHP_SAPI) {
  12. throw new Exception('This script must be run from the command line.');
  13. }
  14. /**
  15. * Starts a dump server to collect and output dumps on a single place with multiple formats support.
  16. *
  17. * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
  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. function includeIfExists(string $file): bool
  28. {
  29. return file_exists($file) && include $file;
  30. }
  31. if (
  32. !includeIfExists(__DIR__ . '/../../../../autoload.php') &&
  33. !includeIfExists(__DIR__ . '/../../vendor/autoload.php') &&
  34. !includeIfExists(__DIR__ . '/../../../../../../vendor/autoload.php')
  35. ) {
  36. fwrite(STDERR, 'Install dependencies using Composer.'.PHP_EOL);
  37. exit(1);
  38. }
  39. if (!class_exists(Application::class)) {
  40. fwrite(STDERR, 'You need the "symfony/console" component in order to run the VarDumper server.'.PHP_EOL);
  41. exit(1);
  42. }
  43. $input = new ArgvInput();
  44. $output = new ConsoleOutput();
  45. $defaultHost = '127.0.0.1:9912';
  46. $host = $input->getParameterOption(['--host'], $_SERVER['VAR_DUMPER_SERVER'] ?? $defaultHost, true);
  47. $logger = interface_exists(LoggerInterface::class) ? new ConsoleLogger($output->getErrorOutput()) : null;
  48. $app = new Application();
  49. $app->getDefinition()->addOption(
  50. new InputOption('--host', null, InputOption::VALUE_REQUIRED, 'The address the server should listen to', $defaultHost)
  51. );
  52. $app->add($command = new ServerDumpCommand(new DumpServer($host, $logger)))
  53. ->getApplication()
  54. ->setDefaultCommand($command->getName(), true)
  55. ->run($input, $output)
  56. ;