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

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\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 $configsContainerBuilder $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 (str_starts_with($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. }