@@ -97,12 +97,7 @@ Dumpers
97
97
98
98
A dumper is responsible for outputting a string representation of a PHP variable,
99
99
using a :class: `Symfony\\ Component\\ VarDumper\\ Cloner\\ Data ` object as input.
100
- The destination and the formatting of this output vary with dumpers and are
101
- influenced by two environment variables:
102
-
103
- * If ``DUMP_STRING_LENGTH `` is set, then the length of a string is displayed
104
- next to its content.
105
- * If ``DUMP_LIGHT_ARRAY `` is set, then arrays are not displayed completely.
100
+ The destination and the formatting of this output vary with dumpers.
106
101
107
102
This component comes with an :class: `Symfony\\ Component\\ VarDumper\\ Dumper\\ HtmlDumper `
108
103
for HTML output and a :class: `Symfony\\ Component\\ VarDumper\\ Dumper\\ CliDumper `
@@ -202,6 +197,74 @@ providing a third parameter when calling ``dump``::
202
197
203
198
// Limit nesting to 1 level and string length to 160 characters (default)
204
199
200
+ The output format of a dumper can be fine tuned by the two flags ``DUMP_STRING_LENGTH ``
201
+ and ``DUMP_LIGHT_ARRAY `` which are passed as a bitmap in the third constructor argument.
202
+ They can also be set via environment variables when using ``assertDumpEquals `` of the
203
+ :class: `Symfony\\ Component\\ VarDumper\\ Test\\ VarDumperTestTrait ` during unit testing.
204
+ The flags can be configured in :file: `phpunit.xml.dist `.
205
+
206
+ * If ``DUMP_STRING_LENGTH `` is set, then the length of a string is displayed
207
+ next to its content.
208
+
209
+ ::
210
+
211
+ use Symfony\Component\VarDumper\Dumper\AbstractDumper;
212
+ use Symfony\Component\VarDumper\Dumper\CliDumper;
213
+
214
+ $var = array('test');
215
+ $dumper = new CliDumper();
216
+ echo $dumper->dump($var, true);
217
+
218
+ // array:1 [
219
+ // 0 => "test"
220
+ // ]
221
+
222
+ $dumper = new CliDumper(null, null, AbstractDumper::DUMP_STRING_LENGTH);
223
+ echo $dumper->dump($var, true);
224
+
225
+ // (added string length before the string)
226
+ // array:1 [
227
+ // 0 => (4) "test"
228
+ // ]
229
+
230
+ * If ``DUMP_LIGHT_ARRAY `` is set, then arrays are dumped in a shortened format.
231
+
232
+ ::
233
+
234
+ use Symfony\Component\VarDumper\Dumper\AbstractDumper;
235
+ use Symfony\Component\VarDumper\Dumper\CliDumper;
236
+
237
+ $var = array('test');
238
+ $dumper = new CliDumper();
239
+ echo $dumper->dump($var, true);
240
+
241
+ // array:1 [
242
+ // 0 => "test"
243
+ // ]
244
+
245
+ $dumper = new CliDumper(null, null, AbstractDumper::DUMP_LIGHT_ARRAY);
246
+ echo $dumper->dump($var, true);
247
+
248
+ // (no more array:1 prefix)
249
+ // [
250
+ // 0 => "test"
251
+ // ]
252
+
253
+ * If you would like to use both options, then you can just combine them by using a the logical OR operator ``| ``.
254
+
255
+ ::
256
+
257
+ use Symfony\Component\VarDumper\Dumper\AbstractDumper;
258
+ use Symfony\Component\VarDumper\Dumper\CliDumper;
259
+
260
+ $var = array('test');
261
+ $dumper = new CliDumper(null, null, AbstractDumper::DUMP_STRING_LENGTH | AbstractDumper::DUMP_LIGHT_ARRAY);
262
+ echo $dumper->dump($var, true);
263
+
264
+ // [
265
+ // 0 => (4) "test"
266
+ // ]
267
+
205
268
Casters
206
269
-------
207
270
0 commit comments