@@ -91,6 +91,8 @@ current PHP SAPI:
9191 .. versionadded :: 4.1
9292 The ``dd() `` helper method was introduced in Symfony 4.1.
9393
94+ .. _var-dumper-dump-server :
95+
9496The Dump Server
9597---------------
9698
@@ -117,22 +119,72 @@ server, which outputs it to its own console or to an HTML file:
117119
118120 Inside a Symfony application, the output of the dump server is configured with
119121the :ref: `dump_destination option <configuration-debug-dump_destination >` of the
120- ``debug `` package.
122+ ``debug `` package:
123+
124+ .. configuration-block ::
125+
126+ .. code-block :: yaml
127+
128+ # config/packages/debug.yaml
129+ debug :
130+ dump_destination : " tcp://%env(VAR_DUMPER_SERVER)%"
131+
132+ .. code-block :: xml
121133
122- Outside a Symfony application, use the ``ServerDumper `` class::
134+ <!-- config/packages/debug.xml -->
135+ <?xml version =" 1.0" encoding =" UTF-8" ?>
136+ <container xmlns =" http://symfony.com/schema/dic/debug"
137+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
138+ xmlns : debug =" http://symfony.com/schema/dic/debug"
139+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
140+ http://symfony.com/schema/dic/services/services-1.0.xsd
141+ http://symfony.com/schema/dic/debug http://symfony.com/schema/dic/debug/debug-1.0.xsd" >
142+
143+ <debug : config dump-destination =" tcp://%env(VAR_DUMPER_SERVER)%" />
144+ </container >
145+
146+ .. code-block :: php
147+
148+ // config/packages/debug.php
149+ $container->loadFromExtension('debug', array(
150+ 'dump_destination' => 'tcp://%env(VAR_DUMPER_SERVER)%',
151+ ));
152+
153+ Outside a Symfony application, use the :class: `Symfony\\ Component\\ VarDumper\\ Dumper\\ ServerDumper ` class::
123154
124155 require __DIR__.'/vendor/autoload.php';
125156
126157 use Symfony\Component\VarDumper\VarDumper;
127158 use Symfony\Component\VarDumper\Cloner\VarCloner;
128159 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));
160+
161+ $cloner = new VarCloner();
162+ $fallbackDumper = \in_array(\PHP_SAPI, array('cli', 'phpdbg')) ? new CliDumper() : new HtmlDumper();
163+ $dumper = new ServerDumper('tcp://127.0.0.1:9912', $fallbackDumper, [
164+ 'cli' => new CliContextProvider(),
165+ 'source' => new SourceContextProvider(),
166+ ]);
167+
168+ VarDumper::setHandler(function ($var) use ($cloner, $dumper) {
169+ $dumper->dump($cloner->cloneVar($var));
134170 });
135171
172+
173+ .. note ::
174+
175+ The :class: `Symfony\\ Component\\ VarDumper\\ Dumper\\ ServerDumper ` accepts as second argument
176+ a :class: `Symfony\\ Component\\ VarDumper\\ Dumper\\ DataDumperInterface ` instance
177+ as a fallback for whenever the server is unreachable and context providers as third argument.
178+ These providers allow to gather some info about the context in which was dumped the data.
179+ Built-in contexts providers are: ``cli ``, ``request `` and ``source ``.
180+
181+ Then you can use the following command to start a server out-of-the-box:
182+
183+ .. code-block :: terminal
184+
185+ $ ./vendor/bin/var-dump-server
186+ [OK] Server listening on tcp://127.0.0.1:9912
187+
136188 DebugBundle and Twig Integration
137189--------------------------------
138190
0 commit comments