5
5
The PropertyInfo Component
6
6
==========================
7
7
8
- The PropertyInfo component provides the functionality to get information
9
- about class properties using metadata of popular sources .
8
+ The PropertyInfo component allows you to get information
9
+ about class properties by using different sources of metadata .
10
10
11
11
While the :doc: `PropertyAccess component </components/property_access >`
12
12
allows you to read and write values to/from objects and arrays, the PropertyInfo
13
- component works solely with class definitions to provide information such
14
- as data type and visibility about properties within that class.
15
-
16
- Similar to PropertyAccess, the PropertyInfo component combines both class
17
- properties (such as ``$property ``) and properties defined via accessor and
18
- mutator methods such as ``getProperty() ``, ``isProperty() ``, ``setProperty() ``,
19
- ``addProperty() ``, ``removeProperty() ``, etc.
13
+ component works solely with class definitions to provide information about the
14
+ data type and visibility - including via getter or setter methods - of the properties
15
+ within that class.
20
16
21
17
.. versionadded :: 2.8
22
18
The PropertyInfo component was introduced in Symfony 2.8.
@@ -42,22 +38,40 @@ Additional dependencies may be required for some of the
42
38
Usage
43
39
-----
44
40
45
- The entry point of this component is a new instance of the
46
- :class: `Symfony\\ Component\\ PropertyInfo\\ PropertyInfoExtractor `
47
- class, providing sets of information extractors.
41
+ To use this component, create a new
42
+ :class: `Symfony\\ Component\\ PropertyInfo\\ PropertyInfoExtractor ` instance and
43
+ provide it with a set of information extractors.
48
44
49
45
.. code-block :: php
50
46
51
47
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
48
+ use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
49
+ use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
50
+
51
+ // a full list of extractors is shown further below
52
+ $phpDocExtractor = new PhpDocExtractor();
53
+ $reflectionExtractor = new ReflectionExtractor();
54
+
55
+ // array of PropertyListExtractorInterface
56
+ $listExtractors = array($reflectionExtractor);
57
+
58
+ // array of PropertyTypeExtractorInterface
59
+ $typeExtractors = array($phpDocExtractor, $reflectionExtractor);
60
+
61
+ // array of PropertyDescriptionExtractorInterface
62
+ $descriptionExtractors = array($phpDocExtractor);
63
+
64
+ // array of PropertyAccessExtractorInterface
65
+ $accessExtractors = array($reflectionExtractor);
52
66
53
67
$propertyInfo = new PropertyInfoExtractor(
54
- $arrayOfListExtractors ,
55
- $arrayOfTypeExtractors ,
56
- $arrayOfDescriptionExtractors ,
57
- $arrayOfAccessExtractors
68
+ $listExtractors ,
69
+ $typeExtractors ,
70
+ $descriptionExtractors ,
71
+ $accessExtractors
58
72
);
59
73
60
- The order of extractor instances within an array matters, as the first non-null
74
+ The order of extractor instances within an array matters: the first non-null
61
75
result will be returned. That is why you must provide each category of extractors
62
76
as a separate array, even if an extractor provides information for more than
63
77
one category.
@@ -101,7 +115,14 @@ Extractable Information
101
115
-----------------------
102
116
103
117
The :class: `Symfony\\ Component\\ PropertyInfo\\ PropertyInfoExtractor `
104
- class exposes public methods to extract four types of information: list,
118
+ class exposes public methods to extract four types of information:
119
+
120
+ * :ref: `*List* of properties <property-info-list >`: `getProperties() `
121
+ * :ref: `Property *type* <property-info-type >`: `getTypes() `
122
+ * :ref: `Property *description* <property-info-description >`: `getShortDescription() ` and `getLongDescription() `
123
+ * :ref: `Property *access* details <property-info-access >`: `isReadable() ` and `isWritable() `
124
+
125
+ list,
105
126
type, description and access information. The first type of information is
106
127
about the class, while the remaining three are about the individual properties.
107
128
@@ -117,6 +138,8 @@ about the class, while the remaining three are about the individual properties.
117
138
Since the PropertyInfo component requires PHP 5.5 or greater, you can
118
139
also make use of the `class constant `_.
119
140
141
+ .. _property-info-list :
142
+
120
143
List Information
121
144
~~~~~~~~~~~~~~~~
122
145
@@ -137,6 +160,8 @@ containing each property name as a string.
137
160
}
138
161
*/
139
162
163
+ .. _property-info-type :
164
+
140
165
Type Information
141
166
~~~~~~~~~~~~~~~~
142
167
@@ -164,6 +189,8 @@ for a property.
164
189
}
165
190
*/
166
191
192
+ .. _property-info-description :
193
+
167
194
Description Information
168
195
~~~~~~~~~~~~~~~~~~~~~~~
169
196
@@ -189,6 +216,8 @@ strings.
189
216
It can span multiple lines.
190
217
*/
191
218
219
+ .. _property-info-access :
220
+
192
221
Access Information
193
222
~~~~~~~~~~~~~~~~~~
194
223
0 commit comments