Skip to content

Commit 5e0b9bd

Browse files
review effect
1 parent 26edf7a commit 5e0b9bd

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

components/var_dumper.rst

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,8 @@ The VarDumper Component
66
=======================
77

88
The VarDumper component provides mechanisms for walking through any arbitrary PHP variable.
9-
Built on top, it provides a better ``dump()`` function, that you can use instead of ``var_dump()``,
10-
*better* meaning:
9+
Built on top, it provides a better ``dump()`` function that you can use instead of :phpfunction:`var_dump`.
1110

12-
- per object and resource types specialized view to e.g. filter out Doctrine noise
13-
while dumping a single proxy entity, or get more insight on opened files with
14-
``stream_get_meta_data()``.
15-
- configurable output format: HTML, command line with colors or JSON.
16-
- ability to dump internal references, either soft ones (objects or resources)
17-
or hard ones (``=&`` on arrays or objects properties). Repeated occurrences of
18-
the same object/array/resource won't appear again and again anymore. Moreover,
19-
you'll be able to inspected the reference structure of your data.
20-
- ability to operate in the context of an output buffering handler.
2111

2212
.. versionadded:: 2.6
2313
The VarDumper component was introduced in Symfony 2.6.
@@ -33,21 +23,34 @@ You can install the component in 2 different ways:
3323
The dump() function
3424
-------------------
3525

36-
The VarDumper component creates a global ``dump()`` function that is auto-configured out of the box:
26+
The VarDumper component creates a global ``dump()`` function that is configured out of the box:
3727
HTML or CLI output is automatically selected based on the current PHP SAPI.
3828

39-
``dump()`` is just a thin wrapper for ``\Symfony\Component\VarDumper\VarDumper::dump()`` so can you also use it directly.
40-
You can change the behavior of this function by calling ``\Symfony\Component\VarDumper\VarDumper::setHandler($callable)``:
41-
calls to ``dump()`` will then be forwarded to the ``$callable`` given as first argument.
29+
The advantages of this function are:
4230

43-
Advanced usage
31+
- per object and resource types specialized view to e.g. filter out Doctrine internals
32+
while dumping a single proxy entity, or get more insight on opened files with
33+
:phpfunction:`stream_get_meta_data()`.
34+
- configurable output formats: HTML or colored command line output.
35+
- ability to dump internal references, either soft ones (objects or resources)
36+
or hard ones (``=&`` on arrays or objects properties). Repeated occurrences of
37+
the same object/array/resource won't appear again and again anymore. Moreover,
38+
you'll be able to inspect the reference structure of your data.
39+
- ability to operate in the context of an output buffering handler.
40+
41+
``dump()`` is just a thin wrapper for :method:`VarDumper::dump() <Symfony\\Component\\VarDumper\\VarDumper::dump>`
42+
so can you also use it directly. You can change the behavior of this function by calling
43+
:method:`VarDumper::setHandler($callable) <Symfony\\Component\\VarDumper\\VarDumper::setHandler>`:
44+
calls to ``dump()`` will then be forwarded to ``$callable``, given as first argument.
45+
46+
Advanced Usage
4447
--------------
4548

4649
Cloners
4750
~~~~~~~
4851

4952
A cloner is used to create an intermediate representation of any PHP variable.
50-
Its output is a Data object that wraps this representation.
53+
Its output is a :class:`Data <Symfony\\Component\\VarDumper\\Cloner\\Data>` object that wraps this representation.
5154
A cloner also applies limits when creating the representation, so that the corresponding
5255
Data object could represent only a subset of the cloned variable.
5356

@@ -61,26 +64,27 @@ Before cloning, you can configure the limits with::
6164
$cloner->setMaxItems($number);
6265
$cloner->setMaxString($number);
6366

64-
These limits will be applied when calling ``->cloneVar()`` afterwise.
67+
They will be applied when calling ``->cloneVar()`` afterwards.
6568

6669
Casters
6770
~~~~~~~
6871

6972
Objects and resources nested in a PHP variable are casted to arrays in the intermediate Data representation.
7073
You can tweak the array representation for each object/resource by hooking a Caster into this process.
71-
The component already has a many casters for base PHP classes and other common classes.
74+
The component already includes many casters for base PHP classes and other common classes.
7275

73-
If you want to build your how Caster, you can register one before cloning a PHP variable.
76+
If you want to build your own Caster, you can register one before cloning a PHP variable.
7477
Casters are registered using either a Cloner's constructor or its ``addCasters()`` method::
7578

7679
$myCasters = array(...);
7780
$cloner = new PhpCloner($myCasters);
7881

79-
or::
82+
// or
8083

8184
$cloner->addCasters($myCasters);
8285

83-
The provided ``$myCasters`` argument is an array that maps a class, an interface or a resource type to a callable::
86+
The provided ``$myCasters`` argument is an array that maps a class,
87+
an interface or a resource type to a callable::
8488

8589
$myCasters = array(
8690
'FooClass' => $myFooClassCallableCaster,
@@ -96,26 +100,24 @@ Several casters can also be registered for the same resource type/class/interfac
96100
They are called in registration order.
97101

98102
Casters are responsible for returning the properties of the object or resource being cloned in an array.
99-
They are callables that accept four arguments::
100-
101-
/**
102-
* A caster not doing anything.
103-
*
104-
* @param object|resource $object The object or resource being casted.
105-
* @param array $array An array modelled for objects after PHP's native `(array)` cast operator.
106-
* @param Stub $stub A Cloner\Stub object representing the main properties of $object (class, type, etc.).
107-
* @param bool $isNested True/false when the caster is called nested is a structure or not.
108-
*
109-
* @return array The properties of $object casted in an array.
110-
*/
111-
function myCaster($origValue, $array, $stub, $isNested)
103+
They are callables that accept four arguments:
104+
105+
- the object or resource being casted,
106+
- an array modelled for objects after PHP's native ``(array)`` cast operator,
107+
- a :class:`Stub <Sumfony\\Component\\VarDumper\\Cloner\\Stub>` object representing
108+
the main properties of the object (class, type, etc.),
109+
- true/false when the caster is called nested is a structure or not.
110+
111+
Here is a simple caster not doing anything::
112+
113+
function myCaster($object, $array, $stub, $isNested)
112114
{
113-
// Here, populate/alter $array to your needs.
115+
// ... populate/alter $array to your needs
114116

115117
return $array;
116118
}
117119

118-
For objects, the ``$array`` parameter comes pre-populated with PHP's native ``(array)`` casting operator,
120+
For objects, the ``$array`` parameter comes pre-populated with PHP's native ``(array)`` casting operator
119121
or with the return value of ``$object->__debugInfo()`` if the magic method exists.
120122
Then, the return value of one Caster is given as argument to the next Caster in the chain.
121123

0 commit comments

Comments
 (0)