diff --git a/components/property_info.rst b/components/property_info.rst index 0b240497dc5..ca627bdcb03 100644 --- a/components/property_info.rst +++ b/components/property_info.rst @@ -50,29 +50,36 @@ provide it with a set of information extractors. $phpDocExtractor = new PhpDocExtractor(); $reflectionExtractor = new ReflectionExtractor(); - // array of PropertyListExtractorInterface + // list of PropertyListExtractorInterface (any iterable) $listExtractors = array($reflectionExtractor); - // array of PropertyTypeExtractorInterface + // list of PropertyTypeExtractorInterface (any iterable) $typeExtractors = array($phpDocExtractor, $reflectionExtractor); - // array of PropertyDescriptionExtractorInterface + // list of PropertyDescriptionExtractorInterface (any iterable) $descriptionExtractors = array($phpDocExtractor); - // array of PropertyAccessExtractorInterface - $accessExtractors = array($reflectionExtractor); + // list of PropertyInitializableExtractorInterface (any iterable) + $propertyInitializableExtractors = array($reflectionExtractor); + + // list of PropertyAccessExtractorInterface (any iterable) $propertyInfo = new PropertyInfoExtractor( $listExtractors, $typeExtractors, $descriptionExtractors, - $accessExtractors + $accessExtractors, + $propertyInitializableExtractors ); // see below for more examples $class = YourAwesomeCoolClass::class; $properties = $propertyInfo->getProperties($class); +.. versionadded:: 4.2 + :class:`Symfony\\Component\\PropertyInfo\\PropertyInitializableExtractorInterface` + was introduced in Symfony 4.2. + Extractor Ordering ~~~~~~~~~~~~~~~~~~ @@ -120,12 +127,13 @@ Extractable Information ----------------------- The :class:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractor` -class exposes public methods to extract four types of information: +class exposes public methods to extract several types of information: -* :ref:`List of properties `: `getProperties()` -* :ref:`Property type `: `getTypes()` -* :ref:`Property description `: `getShortDescription()` and `getLongDescription()` -* :ref:`Property access details `: `isReadable()` and `isWritable()` +* :ref:`List of properties `: :method:`Symfony\\Component\\PropertyInfo\\PropertyListExtractorInterface::getProperties()` +* :ref:`Property type `: :method:`Symfony\\Component\\PropertyInfo\\PropertyTypeExtractorInterface::getTypes()` +* :ref:`Property description `: :method:`Symfony\\Component\\PropertyInfo\\PropertyDescriptionExtractorInterface::getShortDescription()` and :method:`Symfony\\Component\\PropertyInfo\\PropertyDescriptionExtractorInterface::getLongDescription()` +* :ref:`Property access details `: :method:`Symfony\\Component\\PropertyInfo\\PropertyAccessExtractorInterface::isReadable()` and :method:`Symfony\\Component\\PropertyInfo\\PropertyAccessExtractorInterface::isWritable()` +* :ref:`Property initializable through the constructor `: :method:`Symfony\\Component\\PropertyInfo\\PropertyInitializableExtractorInterface::isInitializable()` .. note:: @@ -244,10 +252,27 @@ works. The support of hasser methods in the ``ReflectionExtractor`` class was introduced in Symfony 4.1. +.. _property-info-initializable: + +Property Initializable Information +---------------------------------- + +Extractors that implement :class:`Symfony\\Component\\PropertyInfo\\PropertyInitializableExtractorInterface` +provide whether properties are initializable through the class's constructor as booleans. + +.. code-block:: php + + $propertyInfo->isInitializable($class, $property); + // Example Result: bool(true) + +:method:`Symfony\\Component\\PropertyInfo\\Extractor\\ReflectionExtractor::isInitializable` +returns ``true`` if a constructor's parameter of the given class matches the +given property name. + .. tip:: The main :class:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractor` - class implements all four interfaces, delegating the extraction of property + class implements all interfaces, delegating the extraction of property information to the extractors that have been registered with it. This means that any method available on each of the extractors is also @@ -350,7 +375,8 @@ ReflectionExtractor Using PHP reflection, the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\ReflectionExtractor` provides list, type and access information from setter and accessor methods. -It can also provide return and scalar types for PHP 7+. +It can also give the type of a property, and if it is initializable through the +constructor. It supports return and scalar types for PHP 7. .. note:: @@ -372,12 +398,17 @@ It can also provide return and scalar types for PHP 7+. // List information. $reflectionExtractor->getProperties($class); + // Type information. $reflectionExtractor->getTypes($class, $property); + // Access information. $reflectionExtractor->isReadable($class, $property); $reflectionExtractor->isWritable($class, $property); + // Initializable information + $reflectionExtractor->isInitializable($class, $property); + PhpDocExtractor ~~~~~~~~~~~~~~~ @@ -471,8 +502,9 @@ You can create your own property information extractors by creating a class that implements one or more of the following interfaces: :class:`Symfony\\Component\\PropertyInfo\\PropertyAccessExtractorInterface`, :class:`Symfony\\Component\\PropertyInfo\\PropertyDescriptionExtractorInterface`, -:class:`Symfony\\Component\\PropertyInfo\\PropertyListExtractorInterface` -and :class:`Symfony\\Component\\PropertyInfo\\PropertyTypeExtractorInterface`. +:class:`Symfony\\Component\\PropertyInfo\\PropertyListExtractorInterface`, +:class:`Symfony\\Component\\PropertyInfo\\PropertyTypeExtractorInterface` and +:class:`Symfony\\Component\\PropertyInfo\\PropertyInitializableExtractorInterface`. If you have enabled the PropertyInfo component with the FrameworkBundle, you can automatically register your extractor class with the ``property_info``