Skip to content

Commit b491b0f

Browse files
committed
feature #7217 Document new environment variables and display options (sawmurai, javiereguiluz, Fabian Becker)
This PR was merged into the 3.2 branch. Discussion ---------- Document new environment variables and display options Pull request for ticket #7177 Commits ------- 29080a6 Minor formatting changes 2ef1b60 Fix format 0c46fce Respect 80 chars line length 6b2248e Fix mention of file ad90321 Describe flags in more detail dfb6d6a Trimmed some lines to respect the 80-char soft limit 9340846 Replaced the list to use an unordered list adbec6d Reformat documentation and link to class doc. 7b26e44 Document new environment variables and display options
2 parents f4f815f + 29080a6 commit b491b0f

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

components/var_dumper/advanced.rst

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,94 @@ method. They also typically implement the
181181
them from re-implementing the logic required to walk through a
182182
:class:`Symfony\\Component\\VarDumper\\Cloner\\Data` object's internal structure.
183183

184+
The :class:`Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper` limits string
185+
length and nesting depth of the output to make it more readable. These options
186+
can be overriden by the third optional parameter of the
187+
:method:`dump(Data $data) <Symfony\\Component\\VarDumper\\Dumper\\DataDumperInterface::dump>`
188+
method::
189+
190+
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
191+
192+
$output = fopen('php://memory', 'r+b');
193+
194+
$dumper = new HtmlDumper();
195+
$dumper->dump($var, $output, array(
196+
// 1 and 160 are the default values for these options
197+
'maxDepth' => 1,
198+
'maxStringLength' => 160
199+
));
200+
201+
The output format of a dumper can be fine tuned by the two flags
202+
``DUMP_STRING_LENGTH`` and ``DUMP_LIGHT_ARRAY`` which are passed as a bitmap
203+
in the third constructor argument. They can also be set via environment
204+
variables when using
205+
:method:`assertDumpEquals($dump, $data, $message) <Symfony\\Component\\VarDumper\\Test\\VarDumperTestTrait::assertDumpEquals>`
206+
during unit testing.
207+
208+
If ``DUMP_STRING_LENGTH`` is set, then the length of a string is displayed
209+
next to its content:
210+
211+
.. code-block:: php
212+
213+
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
214+
use Symfony\Component\VarDumper\Dumper\CliDumper;
215+
216+
$var = array('test');
217+
$dumper = new CliDumper();
218+
echo $dumper->dump($var, true);
219+
220+
// array:1 [
221+
// 0 => "test"
222+
// ]
223+
224+
$dumper = new CliDumper(null, null, AbstractDumper::DUMP_STRING_LENGTH);
225+
echo $dumper->dump($var, true);
226+
227+
// (added string length before the string)
228+
// array:1 [
229+
// 0 => (4) "test"
230+
// ]
231+
232+
If ``DUMP_LIGHT_ARRAY`` is set, then arrays are dumped in a shortened format
233+
similar to PHP's short array notation:
234+
235+
.. code-block:: php
236+
237+
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
238+
use Symfony\Component\VarDumper\Dumper\CliDumper;
239+
240+
$var = array('test');
241+
$dumper = new CliDumper();
242+
echo $dumper->dump($var, true);
243+
244+
// array:1 [
245+
// 0 => "test"
246+
// ]
247+
248+
$dumper = new CliDumper(null, null, AbstractDumper::DUMP_LIGHT_ARRAY);
249+
echo $dumper->dump($var, true);
250+
251+
// (no more array:1 prefix)
252+
// [
253+
// 0 => "test"
254+
// ]
255+
256+
If you would like to use both options, then you can just combine them by
257+
using a the logical OR operator ``|``:
258+
259+
.. code-block:: php
260+
261+
use Symfony\Component\VarDumper\Dumper\AbstractDumper;
262+
use Symfony\Component\VarDumper\Dumper\CliDumper;
263+
264+
$var = array('test');
265+
$dumper = new CliDumper(null, null, AbstractDumper::DUMP_STRING_LENGTH | AbstractDumper::DUMP_LIGHT_ARRAY);
266+
echo $dumper->dump($var, true);
267+
268+
// [
269+
// 0 => (4) "test"
270+
// ]
271+
184272
Casters
185273
-------
186274

0 commit comments

Comments
 (0)