Version 1
[yaffs-website] / vendor / symfony / http-kernel / EventListener / DumpListener.php
diff --git a/vendor/symfony/http-kernel/EventListener/DumpListener.php b/vendor/symfony/http-kernel/EventListener/DumpListener.php
new file mode 100644 (file)
index 0000000..06b8a03
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\HttpKernel\EventListener;
+
+use Symfony\Component\Console\ConsoleEvents;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symfony\Component\VarDumper\Cloner\ClonerInterface;
+use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
+use Symfony\Component\VarDumper\VarDumper;
+
+/**
+ * Configures dump() handler.
+ *
+ * @author Nicolas Grekas <p@tchwork.com>
+ */
+class DumpListener implements EventSubscriberInterface
+{
+    private $cloner;
+    private $dumper;
+
+    /**
+     * @param ClonerInterface     $cloner Cloner service
+     * @param DataDumperInterface $dumper Dumper service
+     */
+    public function __construct(ClonerInterface $cloner, DataDumperInterface $dumper)
+    {
+        $this->cloner = $cloner;
+        $this->dumper = $dumper;
+    }
+
+    public function configure()
+    {
+        $cloner = $this->cloner;
+        $dumper = $this->dumper;
+
+        VarDumper::setHandler(function ($var) use ($cloner, $dumper) {
+            $dumper->dump($cloner->cloneVar($var));
+        });
+    }
+
+    public static function getSubscribedEvents()
+    {
+        // Register early to have a working dump() as early as possible
+        return array(ConsoleEvents::COMMAND => array('configure', 1024));
+    }
+}