Skip to content

Commit eac5218

Browse files
authored
Explain dump server usage outside of Symfony
Took hours for me to figure out how to use the dump server outside of Symfony, because there is no mention that it can be done, and one must use the ServerDumper class to make it work.
1 parent 127b35d commit eac5218

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

components/var_dumper.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ Inside a Symfony application, the output of the dump server is configured with
119119
the :ref:`dump_destination option <configuration-debug-dump_destination>` of the
120120
``debug`` package.
121121

122+
Outside a Symfony application, one is required to use the ServerDumper class:
123+
124+
require __DIR__.'/vendor/autoload.php';
125+
126+
use Symfony\Component\VarDumper\VarDumper;
127+
use Symfony\Component\VarDumper\Cloner\VarCloner;
128+
use Symfony\Component\VarDumper\Dumper\ServerDumper;
129+
130+
VarDumper::setHandler(function ($var) {
131+
$cloner = new VarCloner();
132+
$dumper = new ServerDumper('tcp://127.0.0.1:9912');
133+
$dumper->dump($cloner->cloneVar($var));
134+
});
135+
122136
DebugBundle and Twig Integration
123137
--------------------------------
124138

0 commit comments

Comments
 (0)