4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\EventListener;
14 use Symfony\Component\Console\ConsoleEvents;
15 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16 use Symfony\Component\VarDumper\Cloner\ClonerInterface;
17 use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
18 use Symfony\Component\VarDumper\VarDumper;
21 * Configures dump() handler.
23 * @author Nicolas Grekas <p@tchwork.com>
25 class DumpListener implements EventSubscriberInterface
30 public function __construct(ClonerInterface $cloner, DataDumperInterface $dumper)
32 $this->cloner = $cloner;
33 $this->dumper = $dumper;
36 public function configure()
38 $cloner = $this->cloner;
39 $dumper = $this->dumper;
41 VarDumper::setHandler(function ($var) use ($cloner, $dumper) {
42 $dumper->dump($cloner->cloneVar($var));
46 public static function getSubscribedEvents()
48 if (!class_exists(ConsoleEvents::class)) {
52 // Register early to have a working dump() as early as possible
53 return array(ConsoleEvents::COMMAND => array('configure', 1024));