vendor/symfony/debug-bundle/DebugBundle.php line 23

  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;
  11. use Symfony\Bundle\DebugBundle\DependencyInjection\Compiler\DumpDataCollectorPass;
  12. use Symfony\Component\Console\Application;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\HttpKernel\Bundle\Bundle;
  15. use Symfony\Component\VarDumper\VarDumper;
  16. /**
  17.  * @author Nicolas Grekas <p@tchwork.com>
  18.  */
  19. class DebugBundle extends Bundle
  20. {
  21.     /**
  22.      * @return void
  23.      */
  24.     public function boot()
  25.     {
  26.         if ($this->container->getParameter('kernel.debug')) {
  27.             $container $this->container;
  28.             // This code is here to lazy load the dump stack. This default
  29.             // configuration is overridden in CLI mode on 'console.command' event.
  30.             // The dump data collector is used by default, so dump output is sent to
  31.             // the WDT. In a CLI context, if dump is used too soon, the data collector
  32.             // will buffer it, and release it at the end of the script.
  33.             VarDumper::setHandler(function ($varstring $label null) use ($container) {
  34.                 $dumper $container->get('data_collector.dump');
  35.                 $cloner $container->get('var_dumper.cloner');
  36.                 $handler = function ($varstring $label null) use ($dumper$cloner) {
  37.                     $var $cloner->cloneVar($var);
  38.                     if (null !== $label) {
  39.                         $var $var->withContext(['label' => $label]);
  40.                     }
  41.                     $dumper->dump($var);
  42.                 };
  43.                 VarDumper::setHandler($handler);
  44.                 $handler($var$label);
  45.             });
  46.         }
  47.     }
  48.     /**
  49.      * @return void
  50.      */
  51.     public function build(ContainerBuilder $container)
  52.     {
  53.         parent::build($container);
  54.         $container->addCompilerPass(new DumpDataCollectorPass());
  55.     }
  56.     /**
  57.      * @return void
  58.      */
  59.     public function registerCommands(Application $application)
  60.     {
  61.         // noop
  62.     }
  63. }