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

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