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

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