vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/DumpListener.php line 36

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\Component\HttpKernel\EventListener;
  11. use Symfony\Component\Console\ConsoleEvents;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\VarDumper\Cloner\ClonerInterface;
  14. use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
  15. use Symfony\Component\VarDumper\VarDumper;
  16. /**
  17.  * Configures dump() handler.
  18.  *
  19.  * @author Nicolas Grekas <p@tchwork.com>
  20.  */
  21. class DumpListener implements EventSubscriberInterface
  22. {
  23.     private $cloner;
  24.     private $dumper;
  25.     public function __construct(ClonerInterface $clonerDataDumperInterface $dumper)
  26.     {
  27.         $this->cloner $cloner;
  28.         $this->dumper $dumper;
  29.     }
  30.     public function configure()
  31.     {
  32.         $cloner $this->cloner;
  33.         $dumper $this->dumper;
  34.         VarDumper::setHandler(function ($var) use ($cloner$dumper) {
  35.             $dumper->dump($cloner->cloneVar($var));
  36.         });
  37.     }
  38.     public static function getSubscribedEvents()
  39.     {
  40.         if (!class_exists(ConsoleEvents::class)) {
  41.             return array();
  42.         }
  43.         // Register early to have a working dump() as early as possible
  44.         return array(ConsoleEvents::COMMAND => array('configure'1024));
  45.     }
  46. }