@@ -91,6 +91,8 @@ current PHP SAPI:
91
91
.. versionadded :: 4.1
92
92
The ``dd() `` helper method was introduced in Symfony 4.1.
93
93
94
+ .. _var-dumper-dump-server :
95
+
94
96
The Dump Server
95
97
---------------
96
98
@@ -117,22 +119,72 @@ server, which outputs it to its own console or to an HTML file:
117
119
118
120
Inside a Symfony application, the output of the dump server is configured with
119
121
the :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
121
133
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::
123
154
124
155
require __DIR__.'/vendor/autoload.php';
125
156
126
157
use Symfony\Component\VarDumper\VarDumper;
127
158
use Symfony\Component\VarDumper\Cloner\VarCloner;
128
159
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));
134
170
});
135
171
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
+
136
188
DebugBundle and Twig Integration
137
189
--------------------------------
138
190
0 commit comments