vendor/symfony/debug-bundle/DependencyInjection/DebugExtension.php line 51

  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\Console\Command\Command;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. use Symfony\Component\DependencyInjection\Extension\Extension;
  17. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  18. use Symfony\Component\DependencyInjection\Reference;
  19. use Symfony\Component\VarDumper\Caster\ReflectionCaster;
  20. use Symfony\Component\VarDumper\Dumper\CliDumper;
  21. use Symfony\Component\VarDumper\Dumper\HtmlDumper;
  22. /**
  23.  * DebugExtension.
  24.  *
  25.  * @author Nicolas Grekas <p@tchwork.com>
  26.  */
  27. class DebugExtension extends Extension
  28. {
  29.     public function load(array $configsContainerBuilder $container)
  30.     {
  31.         $configuration = new Configuration();
  32.         $config $this->processConfiguration($configuration$configs);
  33.         $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
  34.         $loader->load('services.php');
  35.         $container->getDefinition('var_dumper.cloner')
  36.             ->addMethodCall('setMaxItems', [$config['max_items']])
  37.             ->addMethodCall('setMinDepth', [$config['min_depth']])
  38.             ->addMethodCall('setMaxString', [$config['max_string_length']]);
  39.         if (method_exists(ReflectionCaster::class, 'unsetClosureFileInfo')) {
  40.             $container->getDefinition('var_dumper.cloner')
  41.                 ->addMethodCall('addCasters', [ReflectionCaster::UNSET_CLOSURE_FILE_INFO]);
  42.         }
  43.         if (method_exists(HtmlDumper::class, 'setTheme') && 'dark' !== $config['theme']) {
  44.             $container->getDefinition('var_dumper.html_dumper')
  45.                 ->addMethodCall('setTheme', [$config['theme']]);
  46.         }
  47.         if (null === $config['dump_destination']) {
  48.             $container->getDefinition('var_dumper.command.server_dump')
  49.                 ->setClass(ServerDumpPlaceholderCommand::class)
  50.             ;
  51.         } elseif (str_starts_with($config['dump_destination'], 'tcp://')) {
  52.             $container->getDefinition('debug.dump_listener')
  53.                 ->replaceArgument(2, new Reference('var_dumper.server_connection'))
  54.             ;
  55.             $container->getDefinition('data_collector.dump')
  56.                 ->replaceArgument(4, new Reference('var_dumper.server_connection'))
  57.             ;
  58.             $container->getDefinition('var_dumper.dump_server')
  59.                 ->replaceArgument(0$config['dump_destination'])
  60.             ;
  61.             $container->getDefinition('var_dumper.server_connection')
  62.                 ->replaceArgument(0$config['dump_destination'])
  63.             ;
  64.         } else {
  65.             $container->getDefinition('var_dumper.cli_dumper')
  66.                 ->replaceArgument(0$config['dump_destination'])
  67.             ;
  68.             $container->getDefinition('data_collector.dump')
  69.                 ->replaceArgument(4, new Reference('var_dumper.cli_dumper'))
  70.             ;
  71.             $container->getDefinition('var_dumper.command.server_dump')
  72.                 ->setClass(ServerDumpPlaceholderCommand::class)
  73.             ;
  74.         }
  75.         if (method_exists(CliDumper::class, 'setDisplayOptions')) {
  76.             $container->getDefinition('var_dumper.cli_dumper')
  77.                 ->addMethodCall('setDisplayOptions', [[
  78.                     'fileLinkFormat' => new Reference('debug.file_link_formatter'ContainerBuilder::IGNORE_ON_INVALID_REFERENCE),
  79.                 ]])
  80.             ;
  81.         }
  82.         if (!class_exists(Command::class) || !class_exists(ServerLogCommand::class)) {
  83.             $container->removeDefinition('monolog.command.server_log');
  84.         }
  85.     }
  86.     public function getXsdValidationBasePath(): string|false
  87.     {
  88.         return __DIR__.'/../Resources/config/schema';
  89.     }
  90.     public function getNamespace(): string
  91.     {
  92.         return 'http://symfony.com/schema/dic/debug';
  93.     }
  94. }