DebugExtension.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\DebugBundle\DependencyInjection;
  11. use Symfony\Bridge\Monolog\Command\ServerLogCommand;
  12. use Symfony\Bundle\DebugBundle\Command\ServerDumpPlaceholderCommand;
  13. use Symfony\Component\Config\FileLocator;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Extension\Extension;
  16. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  17. use Symfony\Component\DependencyInjection\Reference;
  18. use Symfony\Component\VarDumper\Caster\ReflectionCaster;
  19. use Symfony\Component\VarDumper\Dumper\CliDumper;
  20. use Symfony\Component\VarDumper\Dumper\HtmlDumper;
  21. /**
  22. * DebugExtension.
  23. *
  24. * @author Nicolas Grekas <p@tchwork.com>
  25. */
  26. class DebugExtension extends Extension
  27. {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function load(array $configs, ContainerBuilder $container)
  32. {
  33. $configuration = new Configuration();
  34. $config = $this->processConfiguration($configuration, $configs);
  35. $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  36. $loader->load('services.php');
  37. $container->getDefinition('var_dumper.cloner')
  38. ->addMethodCall('setMaxItems', [$config['max_items']])
  39. ->addMethodCall('setMinDepth', [$config['min_depth']])
  40. ->addMethodCall('setMaxString', [$config['max_string_length']]);
  41. if (method_exists(ReflectionCaster::class, 'unsetClosureFileInfo')) {
  42. $container->getDefinition('var_dumper.cloner')
  43. ->addMethodCall('addCasters', [ReflectionCaster::UNSET_CLOSURE_FILE_INFO]);
  44. }
  45. if (method_exists(HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) {
  46. $container->getDefinition('var_dumper.html_dumper')
  47. ->addMethodCall('setTheme', [$config['theme']]);
  48. }
  49. if (null === $config['dump_destination']) {
  50. $container->getDefinition('var_dumper.command.server_dump')
  51. ->setClass(ServerDumpPlaceholderCommand::class)
  52. ;
  53. } elseif (0 === strpos($config['dump_destination'], 'tcp://')) {
  54. $container->getDefinition('debug.dump_listener')
  55. ->replaceArgument(2, new Reference('var_dumper.server_connection'))
  56. ;
  57. $container->getDefinition('data_collector.dump')
  58. ->replaceArgument(4, new Reference('var_dumper.server_connection'))
  59. ;
  60. $container->getDefinition('var_dumper.dump_server')
  61. ->replaceArgument(0, $config['dump_destination'])
  62. ;
  63. $container->getDefinition('var_dumper.server_connection')
  64. ->replaceArgument(0, $config['dump_destination'])
  65. ;
  66. } else {
  67. $container->getDefinition('var_dumper.cli_dumper')
  68. ->replaceArgument(0, $config['dump_destination'])
  69. ;
  70. $container->getDefinition('data_collector.dump')
  71. ->replaceArgument(4, new Reference('var_dumper.cli_dumper'))
  72. ;
  73. $container->getDefinition('var_dumper.command.server_dump')
  74. ->setClass(ServerDumpPlaceholderCommand::class)
  75. ;
  76. }
  77. if (method_exists(CliDumper::class, 'setDisplayOptions')) {
  78. $container->getDefinition('var_dumper.cli_dumper')
  79. ->addMethodCall('setDisplayOptions', [[
  80. 'fileLinkFormat' => new Reference('debug.file_link_formatter', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE),
  81. ]])
  82. ;
  83. }
  84. if (!class_exists(ServerLogCommand::class)) {
  85. $container->removeDefinition('monolog.command.server_log');
  86. }
  87. }
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public function getXsdValidationBasePath()
  92. {
  93. return __DIR__.'/../Resources/config/schema';
  94. }
  95. /**
  96. * {@inheritdoc}
  97. */
  98. public function getNamespace()
  99. {
  100. return 'http://symfony.com/schema/dic/debug';
  101. }
  102. }