@@ -6,18 +6,8 @@ The VarDumper Component
6
6
=======================
7
7
8
8
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 `.
11
10
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.
21
11
22
12
.. versionadded :: 2.6
23
13
The VarDumper component was introduced in Symfony 2.6.
@@ -33,21 +23,34 @@ You can install the component in 2 different ways:
33
23
The dump() function
34
24
-------------------
35
25
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:
37
27
HTML or CLI output is automatically selected based on the current PHP SAPI.
38
28
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:
42
30
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
44
47
--------------
45
48
46
49
Cloners
47
50
~~~~~~~
48
51
49
52
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.
51
54
A cloner also applies limits when creating the representation, so that the corresponding
52
55
Data object could represent only a subset of the cloned variable.
53
56
@@ -61,26 +64,27 @@ Before cloning, you can configure the limits with::
61
64
$cloner->setMaxItems($number);
62
65
$cloner->setMaxString($number);
63
66
64
- These limits will be applied when calling ``->cloneVar() `` afterwise .
67
+ They will be applied when calling ``->cloneVar() `` afterwards .
65
68
66
69
Casters
67
70
~~~~~~~
68
71
69
72
Objects and resources nested in a PHP variable are casted to arrays in the intermediate Data representation.
70
73
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.
72
75
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.
74
77
Casters are registered using either a Cloner's constructor or its ``addCasters() `` method::
75
78
76
79
$myCasters = array(...);
77
80
$cloner = new PhpCloner($myCasters);
78
81
79
- or::
82
+ // or
80
83
81
84
$cloner->addCasters($myCasters);
82
85
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::
84
88
85
89
$myCasters = array(
86
90
'FooClass' => $myFooClassCallableCaster,
@@ -96,26 +100,24 @@ Several casters can also be registered for the same resource type/class/interfac
96
100
They are called in registration order.
97
101
98
102
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)
112
114
{
113
- // Here, populate/alter $array to your needs.
115
+ // ... populate/alter $array to your needs
114
116
115
117
return $array;
116
118
}
117
119
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
119
121
or with the return value of ``$object->__debugInfo() `` if the magic method exists.
120
122
Then, the return value of one Caster is given as argument to the next Caster in the chain.
121
123
0 commit comments