@@ -47,6 +47,7 @@ provide it with a set of information extractors.
47
47
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
48
48
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
49
49
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
50
+ use Example\Namespace\YourAwesomeCoolClass;
50
51
51
52
// a full list of extractors is shown further below
52
53
$phpDocExtractor = new PhpDocExtractor();
@@ -71,6 +72,13 @@ provide it with a set of information extractors.
71
72
$accessExtractors
72
73
);
73
74
75
+ // see below for more examples
76
+ $class = YourAwesomeCoolClass::class;
77
+ $properties = $propertyInfo->getProperties($class);
78
+
79
+ Extractor Ordering
80
+ ~~~~~~~~~~~~~~~~~~
81
+
74
82
The order of extractor instances within an array matters: the first non-null
75
83
result will be returned. That is why you must provide each category of extractors
76
84
as a separate array, even if an extractor provides information for more than
@@ -122,21 +130,17 @@ class exposes public methods to extract four types of information:
122
130
* :ref: `Property *description* <property-info-description >`: `getShortDescription() ` and `getLongDescription() `
123
131
* :ref: `Property *access* details <property-info-access >`: `isReadable() ` and `isWritable() `
124
132
125
- list,
126
- type, description and access information. The first type of information is
127
- about the class, while the remaining three are about the individual properties.
128
-
129
133
.. note ::
130
134
131
- When specifiying a class that the PropertyInfo component should work
132
- with, use the fully-qualified class name. Do not directly pass an object
133
- as some extractors (the
134
- :class: `Symfony\\ Component\\ PropertyInfo\\ Extractor\\ SerializerExtractor `
135
- is an example) may not automatically resolve objects to their class
136
- names - use the ``get_class() `` function.
135
+ Be sure to pass a *class * name, not an object to the extractor methods::
136
+
137
+ // bad! It may work, but not with all extractors
138
+ $propertyInfo->getProperties($awesomeObject);
137
139
138
- Since the PropertyInfo component requires PHP 5.5 or greater, you can
139
- also make use of the `class constant `_.
140
+ // Good!
141
+ $propertyInfo->getProperties(get_class($awesomeObject));
142
+ $propertyInfo->getProperties('Example\N amespace\Y ourAwesomeClass');
143
+ $propertyInfo->getProperties(YourAwesomeClass::class);
140
144
141
145
.. _property-info-list :
142
146
@@ -189,6 +193,8 @@ for a property.
189
193
}
190
194
*/
191
195
196
+ See :ref: `components-property-info-type ` for info about the ``Type `` class.
197
+
192
198
.. _property-info-description :
193
199
194
200
Description Information
@@ -232,6 +238,11 @@ provide whether properties are readable or writable as booleans.
232
238
$propertyInfo->isWritable($class, $property);
233
239
// Example Result: bool(false)
234
240
241
+ The :class: `Symfony\\ Component\\ PropertyInfo\\ Extractor\\ ReflectionExtractor ` looks
242
+ for getter/isser/setter method in addition to whether or not a property is public
243
+ to determine if it's accessible. This based on how the :ref: `PropertyAccess </components/property_access >`
244
+ works.
245
+
235
246
.. tip ::
236
247
237
248
The main :class: `Symfony\\ Component\\ PropertyInfo\\ PropertyInfoExtractor `
@@ -248,10 +259,9 @@ Type Objects
248
259
------------
249
260
250
261
Compared to the other extractors, type information extractors provide much
251
- more information than can be represented as simple scalar values - because
252
- of this, type extractors return an array of objects. The array will contain
253
- an instance of the :class: `Symfony\\ Component\\ PropertyInfo\\ Type `
254
- class for each type that the property supports.
262
+ more information than can be represented as simple scalar values. Because
263
+ of this, type extractors return an array of :class: `Symfony\\ Component\\ PropertyInfo\\ Type `
264
+ objects for each type that the property supports.
255
265
256
266
For example, if a property supports both ``integer `` and ``string `` (via
257
267
the ``@return int|string `` annotation),
@@ -265,15 +275,12 @@ class.
265
275
instance. The :class: `Symfony\\ Component\\ PropertyInfo\\ Extractor\\ PhpDocExtractor `
266
276
is currently the only extractor that returns multiple instances in the array.
267
277
268
- Each object will provide 6 attributes; the first four (built-in type, nullable,
269
- class and collection) are scalar values and the last two (collection key
270
- type and collection value type) are more instances of the :class: `Symfony\\ Component\\ PropertyInfo\\ Type `
271
- class again if collection is ``true ``.
278
+ Each object will provide 6 attributes, available in the 6 methods:
272
279
273
280
.. _`components-property-info-type-builtin` :
274
281
275
- Built-in Type
276
- ~~~~~~~~~~~~~
282
+ Type::getBuiltInType()
283
+ ~~~~~~~~~~~~~~~~~~~~~~
277
284
278
285
The :method: `Type::getBuiltinType() <Symfony\\ Component\\ PropertyInfo\\ Type::getBuiltinType> `
279
286
method will return the built-in PHP data type, which can be one of 9 possible
@@ -283,22 +290,22 @@ string values: ``array``, ``bool``, ``callable``, ``float``, ``int``, ``null``,
283
290
Constants inside the :class: `Symfony\\ Component\\ PropertyInfo\\ Type `
284
291
class, in the form ``Type::BUILTIN_TYPE_* ``, are provided for convenience.
285
292
286
- Nullable
287
- ~~~~~~~~
293
+ Type::isNullable()
294
+ ~~~~~~~~~~~~~~~~~~
288
295
289
296
The :method: `Type::isNullable() <Symfony\\ Component\\ PropertyInfo\\ Type::isNullable> `
290
297
method will return a boolean value indicating whether the property parameter
291
298
can be set to ``null ``.
292
299
293
- Class
294
- ~~~~~
300
+ Type::getClassName()
301
+ ~~~~~~~~~~~~~~~~~~~~
295
302
296
303
If the :ref: `built-in PHP data type <components-property-info-type-builtin >`
297
304
is ``object ``, the :method: `Type::getClassName() <Symfony\\ Component\\ PropertyInfo\\ Type::getClassName> `
298
305
method will return the fully-qualified class or interface name accepted.
299
306
300
- Collection
301
- ~~~~~~~~~~
307
+ Type::isCollection()
308
+ ~~~~~~~~~~~~~~~~~~~~
302
309
303
310
The :method: `Type::isCollection() <Symfony\\ Component\\ PropertyInfo\\ Type::isCollection> `
304
311
method will return a boolean value indicating if the property parameter is
@@ -310,8 +317,8 @@ this returns ``true`` if:
310
317
* The mutator method the property is derived from has a prefix of ``add ``
311
318
or ``remove `` (which are defined as the list of array mutator prefixes).
312
319
313
- Collection Key & Value Types
314
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
320
+ Type::getCollectionKeyType() & Type::getCollectionValueType()
321
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
315
322
316
323
If the property is a collection, additional type objects may be returned
317
324
for both the key and value types of the collection (if the information is
@@ -344,13 +351,14 @@ Using PHP reflection, the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\R
344
351
provides list, type and access information from setter and accessor methods.
345
352
It can also provide return and scalar types for PHP 7+.
346
353
347
- This service is automatically registered with the ``property_info `` service.
354
+ This service is automatically registered with the ``property_info `` service in
355
+ the Symfony Framework.
348
356
349
357
.. code-block :: php
350
358
351
359
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
352
360
353
- $reflectionExtractor = new ReflectionExtractor;
361
+ $reflectionExtractor = new ReflectionExtractor() ;
354
362
355
363
// List information.
356
364
$reflectionExtractor->getProperties($class);
@@ -370,13 +378,14 @@ PhpDocExtractor
370
378
Using `phpDocumentor Reflection `_ to parse property and method annotations,
371
379
the :class: `Symfony\\ Component\\ PropertyInfo\\ Extractor\\ PhpDocExtractor `
372
380
provides type and description information. This extractor is automatically
373
- registered with the ``property_info `` providing its dependencies are detected.
381
+ registered with the ``property_info `` in the Symfony Framework *if * the dependent
382
+ library is present.
374
383
375
384
.. code-block :: php
376
385
377
386
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
378
387
379
- $phpDocExtractor = new PhpDocExtractor;
388
+ $phpDocExtractor = new PhpDocExtractor() ;
380
389
381
390
// Type information.
382
391
$phpDocExtractor->getTypes($class, $property);
@@ -391,10 +400,11 @@ SerializerExtractor
391
400
392
401
This extractor depends on the `symfony/serializer `_ library.
393
402
394
- Using groups metadata from the :doc: `Serializer component </components/serializer >`,
403
+ Using :ref: `groups metadata <serializer-using-serialization-groups-annotations >`
404
+ from the :doc: `Serializer component </components/serializer >`,
395
405
the :class: `Symfony\\ Component\\ PropertyInfo\\ Extractor\\ SerializerExtractor `
396
- provides list information. This extractor is not registered automatically
397
- with the ``property_info `` service.
406
+ provides list information. This extractor is * not * registered automatically
407
+ with the ``property_info `` service in the Symfony Framework .
398
408
399
409
.. code-block :: php
400
410
@@ -421,9 +431,8 @@ DoctrineExtractor
421
431
422
432
Using entity mapping data from `Doctrine ORM `_, the
423
433
:class: `Symfony\\ Bridge\\ Doctrine\\ PropertyInfo\\ DoctrineExtractor `
424
- - located in the Doctrine bridge - provides list and type information.
425
- This extractor is not registered automatically with the ``property_info ``
426
- service.
434
+ provides list and type information. This extractor is not registered automatically
435
+ with the ``property_info `` service in the Symfony Framework.
427
436
428
437
.. code-block :: php
429
438
@@ -472,4 +481,3 @@ service by defining it as a service with one or more of the following
472
481
.. _`symfony/serializer` : https://packagist.org/packages/symfony/serializer
473
482
.. _`symfony/doctrine-bridge` : https://packagist.org/packages/symfony/doctrine-bridge
474
483
.. _`doctrine/orm` : https://packagist.org/packages/doctrine/orm
475
- .. _`class constant` : http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class.class
0 commit comments