Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb5b45bc

Browse files
move Dumper section above the Caster one
1 parent2fc3811 commitb5b45bc

File tree

1 file changed

+58
-58
lines changed

1 file changed

+58
-58
lines changed

‎components/var_dumper/advanced.rst

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,64 @@ Before cloning, you can configure the limits with::
2727

2828
They will be applied when calling ``->cloneVar()`` afterwards.
2929

30+
Dumpers
31+
~~~~~~~
32+
33+
A dumper is responsible for outputting a string representation of a PHP variable,
34+
using a:class:`Symfony\\Component\\VarDumper\\Cloner\\Data` object as input.
35+
The destination and the formatting of this output vary with dumpers.
36+
37+
This component comes with an:class:`Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper`
38+
for HTML output and a:class:`Symfony\\Component\\VarDumper\\Dumper\\CliDumper`
39+
for optionally colored command line output.
40+
41+
For example, if you want to dump some ``$variable``, just do::
42+
43+
$cloner = new VarCloner();
44+
$dumper = new CliDumper();
45+
46+
$dumper->dump($cloner->cloneVar($variable));
47+
48+
By using the first argument of the constructor, you can select the output
49+
stream where the dump will be written. By default, the ``CliDumper`` writes
50+
on ``php://stdout`` and the ``HtmlDumper`` on ``php://output``, but any PHP
51+
stream (resource or URL) is acceptable.
52+
53+
Instead of a stream destination, you can also pass it a ``callable`` that
54+
will be called repeatedly for each line generated by a dumper. This
55+
callable can be configured using the first argument of a dumper's constructor,
56+
but also using the
57+
:method:`Symfony\\Component\\VarDumper\\Dumper\\AbstractDumper::setLineDumper`
58+
method or the second argument of the
59+
:method:`Symfony\\Component\\VarDumper\\Dumper\\AbstractDumper::dump` method.
60+
61+
For example, to get a dump as a string in a variable, you can do::
62+
63+
$cloner = new VarCloner();
64+
$dumper = new CliDumper();
65+
$output = '';
66+
67+
$dumper->dump(
68+
$cloner->cloneVar($variable),
69+
function ($line, $depth) use (&$output) {
70+
// A negative depth means "end of dump"
71+
if ($depth >= 0) {
72+
// Adds a two spaces indentation to the line
73+
$output .= str_repeat(' ', $depth).$line."\n";
74+
}
75+
}
76+
);
77+
78+
// $output is now populated with the dump representation of $variable
79+
80+
Dumpers implement the:class:`Symfony\\Component\\VarDumper\\Dumper\\DataDumperInterface`
81+
interface that specifies the
82+
:method:`dump(Data $data) <Symfony\\Component\\VarDumper\\Dumper\\DataDumperInterface::dump>`
83+
method. They also typically implement the
84+
:class:`Symfony\\Component\\VarDumper\\Cloner\\DumperInterface` that frees
85+
them from re-implementing the logic required to walk through a
86+
:class:`Symfony\\Component\\VarDumper\\Cloner\\Data` object's internal structure.
87+
3088
Casters
3189
~~~~~~~
3290

@@ -98,61 +156,3 @@ properties not in the class declaration).
98156
..note::
99157
Although you can, it is best advised not to alter the state of an object
100158
while casting it in a Caster.
101-
102-
Dumpers
103-
~~~~~~~
104-
105-
A dumper is responsible for outputting a string representation of a PHP variable,
106-
using a:class:`Symfony\\Component\\VarDumper\\Cloner\\Data` object as input.
107-
The destination and the formatting of this output vary with dumpers.
108-
109-
This component comes with an:class:`Symfony\\Component\\VarDumper\\Dumper\\HtmlDumper`
110-
for HTML output and a:class:`Symfony\\Component\\VarDumper\\Dumper\\CliDumper`
111-
for optionally colored command line output.
112-
113-
For example, if you want to dump some ``$variable``, just do::
114-
115-
$cloner = new VarCloner();
116-
$dumper = new CliDumper();
117-
118-
$dumper->dump($cloner->cloneVar($variable));
119-
120-
By using the first argument of the constructor, you can select the output
121-
stream where the dump will be written. By default, the ``CliDumper`` writes
122-
on ``php://stdout`` and the ``HtmlDumper`` on ``php://output``, but any PHP
123-
stream (resource or URL) is acceptable.
124-
125-
Instead of a stream destination, you can also pass it a ``callable`` that
126-
will be called repeatedly for each line generated by a dumper. This
127-
callable can be configured using the first argument of a dumper's constructor,
128-
but also using the
129-
:method:`Symfony\\Component\\VarDumper\\Dumper\\AbstractDumper::setLineDumper`
130-
method or using the second argument of the
131-
:method:`Symfony\\Component\\VarDumper\\Dumper\\AbstractDumper::dump` method.
132-
133-
For example, to get a dump in a variable, you can do::
134-
135-
$cloner = new VarCloner();
136-
$dumper = new CliDumper();
137-
$output = '';
138-
139-
$dumper->dump(
140-
$cloner->cloneVar($variable),
141-
function ($line, $depth) use (&$output) {
142-
// A negative depth means "end of dump"
143-
if ($depth >= 0) {
144-
// Adds a two spaces indentation to the line
145-
$output .= str_repeat(' ', $depth).$line."\n";
146-
}
147-
}
148-
);
149-
150-
// $output is now populated with the dump representation of $variable
151-
152-
Dumpers implement the:class:`Symfony\\Component\\VarDumper\\Dumper\\DataDumperInterface`
153-
interface that specifies the
154-
:method:`dump(Data $data) <Symfony\\Component\\VarDumper\\Dumper\\DataDumperInterface::dump>`
155-
method. They also typically implement the
156-
:class:`Symfony\\Component\\VarDumper\\Cloner\\DumperInterface` that frees
157-
them from re-implementing the logic required to walk through a
158-
:class:`Symfony\\Component\\VarDumper\\Cloner\\Data` object's internal structure.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp