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