From 8b367457ea36aaf3061b956a8cfe7caa5a257c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 22 Sep 2015 17:17:00 +0200 Subject: [PATCH 1/3] [PropertyInfo] Add the doc --- components/map.rst.inc | 4 + components/property_info.rst | 294 +++++++++++++++++++++++++++++++++++ 2 files changed, 298 insertions(+) create mode 100644 components/property_info.rst diff --git a/components/map.rst.inc b/components/map.rst.inc index dfead75f62c..8c5b76d246f 100644 --- a/components/map.rst.inc +++ b/components/map.rst.inc @@ -119,6 +119,10 @@ * :doc:`/components/property_access/introduction` +* **PropertyInfo** + + * :doc:`/components/property_info` + * :doc:`/components/routing/index` * :doc:`/components/routing/introduction` diff --git a/components/property_info.rst b/components/property_info.rst new file mode 100644 index 00000000000..11ed900fcdd --- /dev/null +++ b/components/property_info.rst @@ -0,0 +1,294 @@ +.. index:: + single: PropertyInfo + single: Components; PropertInfo + +The PropertyInfo Component +========================== + + The PropertyInfo component extracts information about PHP class' properties + using metadata of popular sources. + +The PropertyInfo component is able to extract the following information: + +* List of properties exposed by a class +* Types of a property +* It's short and long DockBlock description +* If the property is readable or writable + +To do so, the component use extractors. It natively support the following +metadata sources: + +* ``ReflectionExtractor``: use the PHP Reflection API (setter type hint, + return and scalar type hint for PHP 7+, accessor methods) +* ``PhpDocExtractor``: use the PHPDoc of properties and accessor methods +* ``DoctrineExtractor``: use metadata provided by the Doctrine ORM +* ``SerializerExtractor``: use groups metadata of the Serializer component + +Custom extractors can be also be registered. + +Installation +------------ + +You can install the component in 2 different ways: + +* :doc:`Install it via Composer ` (``symfony/property-info`` + on `Packagist`_); +* Use the official Git repository (https://github.com/symfony/PropertyInfo). + +.. include:: /components/require_autoload.rst.inc + +To use the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\PhpDocExtractor`, +install `phpDocumentator Reflection`_. +To use the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\SerializerExtractor` +extractor, install the :doc:`Serializer component `. +To use the :class:`Symfony\\Bridge\\Doctrine\\PropertyInfo\\DoctrineExtractor`, +install the Doctrine Bridge and the `Doctrine ORM`_. + +Usage +----- + +Using the PropertyInfo component is straightforward. You need to register +all metadata extractors you want to use in the constructor of the :class:`Symfony\\Component\\PropertyInfo\\PropertyInfo` +class:: + + use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; + use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; + use Symfony\Component\PropertyInfo\PropertyInfo; + + $reflectionExtractor = new ReflectionExtractor(); + $phpDocExtractor = new PhpDocExtractor(); + + $propertyInfo = new PropertyInfo( + array($reflectionExtractor), + array($phpDocExtractor, $reflectionExtractor), + array($phpDocExtractor), + array($reflectionExtractor) + ); + +An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyListRetrieverInterface` +must be passed as first parameter. These extractors are responsible of extracting +the list of properties of a class. + +An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyTypeInfoInterface` +must be passed as second parameter. These extractors are responsible of extracting +types of a property. + +An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyDescriptionInfoInterface` +must be passed as third parameter. These extractors are responsible of extracting +short and long DocBlock description of a property. + +Finaly, an array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyAccessInfoInterface` +must be passed as fourth parameter. These extractors are responsible of guessing +if a property is readable or writable. + +The order of registration matter: the data returned will be the one returned +by the first extractor if different than ``null``. + + +Once instantiated, the ``PropertyInfo`` class can be used to retrieve info +about properties of a class:: + + class MyClass + { + /** + * The short description of foo. + * + * And here is its extended description. + * + * @var string + */ + public $foo; + + /** + * Virtual property. + */ + private function setBar(array $bar) + { + } + } + + var_dump($propertyInfo->getProperties('MyClass')); + var_dump($propertyInfo->getTypes('MyClass', 'foo')); + var_dump($propertyInfo->getTypes('MyClass', 'bar')); + var_dump($propertyInfo->isReadable('MyClass', 'foo')); + var_dump($propertyInfo->isReadable('MyClass', 'bar')); + var_dump($propertyInfo->isWritable('MyClass', 'foo')); + var_dump($propertyInfo->getShortDescription('MyClass', 'bar')); + var_dump($propertyInfo->getLongDescription('MyClass', 'foo')); + + /* + Output: + array(1) { + [0] => + string(3) "foo" + } + array(1) { + [0] => + class Symfony\Component\PropertyInfo\Type#7 (6) { + private $builtinType => + string(6) "string" + private $nullable => + bool(false) + private $class => + NULL + private $collection => + bool(false) + private $collectionKeyType => + NULL + private $collectionValueType => + NULL + } + } + array(1) { + [0] => + class Symfony\Component\PropertyInfo\Type#129 (6) { + private $builtinType => + string(5) "array" + private $nullable => + bool(false) + private $class => + NULL + private $collection => + bool(true) + private $collectionKeyType => + NULL + private $collectionValueType => + NULL + } + } + bool(true) + bool(false) + bool(true) + string(17) "Virtual property." + string(37) "And here is its extended description." + */ + +As PHP doesn't support explicit type definition, ``PropertyInfo::getTypes`` +use registered extractors to an array of :class:`Symfony\\Component\\PropertyInfo\\Type` +value objects. +Those object represent complex PHP types. Refer to the API documentation +of this class for more details. + +Extractors +---------- + +Symfony is shipped with two extractors in addition to the already presented +``ReflectionExtractor`` and ``PhpDocExtractors``. +Moreover, custom extractors can be created by implementing the extractor +interfaces provided with the PropertyInfo component. + +The ``DoctrineExtractor`` +~~~~~~~~~~~~~~~~~~~~~~~~~ + +The Doctrine extractor reuse metadata of the Doctrine ORM to extract the +list of properties and their type. It implements ``PropertyListRetrieverInterface`` +and ``PropertyTypeInfoInterface`` interfaces. + +Instantiate it:: + + use Doctrine\ORM\EntityManager; + use Doctrine\ORM\Tools\Setup; + use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor; + + $config = Setup::createAnnotationMetadataConfiguration([__DIR__], true); + $entityManager = EntityManager::create([ + 'driver' => 'pdo_sqlite', + // ... + ], $config); + + $doctrineExtractor = new DoctrineExtractor($entityManager->getMetadataFactory()); + +You can now use it to retrieve information about an entity mapped with Doctrine:: + + use Doctrine\ORM\Mapping\Column; + use Doctrine\ORM\Mapping\Entity; + use Doctrine\ORM\Mapping\Id; + + /** + * @Entity + */ + class MyEntity + { + /** + * @Id + * @Column(type="integer") + */ + public $id; + } + + var_dump($doctrineExtractor->getProperties('MyEntity')); + var_dump($doctrineExtractor->getTypes('MyEntity', 'id')); + + /* + Output: + + array(1) { + [0] => + string(2) "id" + } + array(1) { + [0] => + class Symfony\Component\PropertyInfo\Type#27 (6) { + private $builtinType => + string(3) "int" + private $nullable => + bool(false) + private $class => + NULL + private $collection => + bool(false) + private $collectionKeyType => + NULL + private $collectionValueType => + NULL + } + } + */ + +Of course you can also register this extractor in the ``PropertyInfo`` class:: + + $propertyInfo = new PropertyInfo( + array($reflectionExtractor, $doctrineExtractor), + array($doctrineExtractor, $phpDocExtractor, $reflectionExtractor) + ); + +The ``SerializerExtractor`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``SerializerExtractor`` leverages groups metadata of the Symfony Serializer +Component (2.7+) to list properties having the groups passed in the context. + +Instantiate it:: + + use Doctrine\Common\Annotations\AnnotationReader; + use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor; + use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; + use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; + + $serializerClassMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); + $serializerExtractor = new SerializerExtractor($serializerClassMetadataFactory); + +Usage:: + + use Symfony\Component\Serializer\Annotation\Groups; + + class Foo + { + /** + * @Groups({"a", "b"}) + */ + public $bar; + public $baz; + } + + $serializerExtractor->getProperties('Foo', array('serializer_groups' => array('a'))); + /* + Output: + array(1) { + [0] => + string(2) "bar" + } + */ + +.. _`phpDocumentator Reflection`: https://github.com/phpDocumentor/Reflection +.. _`Doctrine ORM`: http://www.doctrine-project.org/projects/orm.html From dfa5c45f4efd6ee5443742bffe601a98ac9b7af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 6 Oct 2015 22:18:25 +0200 Subject: [PATCH 2/3] Sync with the merged version --- components/index.rst | 1 + components/property_info.rst | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/index.rst b/components/index.rst index 41f72d049a4..ca449960d25 100644 --- a/components/index.rst +++ b/components/index.rst @@ -24,6 +24,7 @@ The Components options_resolver process property_access/index + property_info routing/index security/index serializer diff --git a/components/property_info.rst b/components/property_info.rst index 11ed900fcdd..9ca380b3c80 100644 --- a/components/property_info.rst +++ b/components/property_info.rst @@ -65,19 +65,19 @@ class:: array($reflectionExtractor) ); -An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyListRetrieverInterface` +An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyListExtractorInterface` must be passed as first parameter. These extractors are responsible of extracting the list of properties of a class. -An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyTypeInfoInterface` +An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyTypeExtractorInterface` must be passed as second parameter. These extractors are responsible of extracting types of a property. -An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyDescriptionInfoInterface` +An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyDescriptionExtractorInterface` must be passed as third parameter. These extractors are responsible of extracting short and long DocBlock description of a property. -Finaly, an array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyAccessInfoInterface` +Finally, an array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyAccessExtractorInterface` must be passed as fourth parameter. These extractors are responsible of guessing if a property is readable or writable. @@ -181,8 +181,8 @@ The ``DoctrineExtractor`` ~~~~~~~~~~~~~~~~~~~~~~~~~ The Doctrine extractor reuse metadata of the Doctrine ORM to extract the -list of properties and their type. It implements ``PropertyListRetrieverInterface`` -and ``PropertyTypeInfoInterface`` interfaces. +list of properties and their type. It implements ``PropertyListExtractorInterface`` +and ``PropertyTypeExtractorInterface`` interfaces. Instantiate it:: @@ -290,5 +290,6 @@ Usage:: } */ +.. _`Packagist`: https://packagist.org/packages/symfony/property-info .. _`phpDocumentator Reflection`: https://github.com/phpDocumentor/Reflection .. _`Doctrine ORM`: http://www.doctrine-project.org/projects/orm.html From 73b8d17b5d5cff1cfeef9c8eba9662d77a11c882 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 18 Dec 2015 17:22:06 +0100 Subject: [PATCH 3/3] Finish the documentation of PropertyInfo --- components/property_info.rst | 250 ++++++++++++++++++----------------- 1 file changed, 128 insertions(+), 122 deletions(-) diff --git a/components/property_info.rst b/components/property_info.rst index 9ca380b3c80..bb8cbe668e7 100644 --- a/components/property_info.rst +++ b/components/property_info.rst @@ -5,26 +5,28 @@ The PropertyInfo Component ========================== - The PropertyInfo component extracts information about PHP class' properties - using metadata of popular sources. + The PropertyInfo component extracts information about the properties of PHP + classes using different sources of metadata. -The PropertyInfo component is able to extract the following information: +The PropertyInfo component extracts the following information: -* List of properties exposed by a class -* Types of a property -* It's short and long DockBlock description -* If the property is readable or writable +* List of properties exposed by a class; +* Type of each property (``int``, ``array``, ``callable``, etc.); +* The short and long DockBlock description (if available); +* Whether the property is readable and/or writable. -To do so, the component use extractors. It natively support the following -metadata sources: +This information is obtained using several *extractors*, which work by parsing +different sources of properties metadata: -* ``ReflectionExtractor``: use the PHP Reflection API (setter type hint, - return and scalar type hint for PHP 7+, accessor methods) -* ``PhpDocExtractor``: use the PHPDoc of properties and accessor methods -* ``DoctrineExtractor``: use metadata provided by the Doctrine ORM -* ``SerializerExtractor``: use groups metadata of the Serializer component +* ``ReflectionExtractor``: uses the built-in PHP Reflection API to parse setter + type hints, return and scalar type hints (for PHP 7+) and accessor methods + (*getXxx()*, *hasXxx()*, *isXxx()*); +* ``PhpDocExtractor``: parses the PHPDoc of properties and accessor methods; +* ``DoctrineExtractor``: gets the metadata provided by the Doctrine ORM; +* ``SerializerExtractor``: gets groups metadata from the Serializer component. -Custom extractors can be also be registered. +Besides these built-in extractors, you can create your own custom extractors, +as explained in the following sections. Installation ------------ @@ -37,18 +39,21 @@ You can install the component in 2 different ways: .. include:: /components/require_autoload.rst.inc -To use the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\PhpDocExtractor`, +Optional dependencies +~~~~~~~~~~~~~~~~~~~~~ + +* To use the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\PhpDocExtractor`, install `phpDocumentator Reflection`_. -To use the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\SerializerExtractor` +* To use the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\SerializerExtractor` extractor, install the :doc:`Serializer component `. -To use the :class:`Symfony\\Bridge\\Doctrine\\PropertyInfo\\DoctrineExtractor`, +* To use the :class:`Symfony\\Bridge\\Doctrine\\PropertyInfo\\DoctrineExtractor`, install the Doctrine Bridge and the `Doctrine ORM`_. Usage ----- -Using the PropertyInfo component is straightforward. You need to register -all metadata extractors you want to use in the constructor of the :class:`Symfony\\Component\\PropertyInfo\\PropertyInfo` +Before using the PropertyInfo component, you need to register the extractors by +passing them to the constructor of the :class:`Symfony\\Component\\PropertyInfo\\PropertyInfo` class:: use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; @@ -65,28 +70,26 @@ class:: array($reflectionExtractor) ); -An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyListExtractorInterface` -must be passed as first parameter. These extractors are responsible of extracting -the list of properties of a class. - -An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyTypeExtractorInterface` -must be passed as second parameter. These extractors are responsible of extracting -types of a property. +The **first argument** must be an array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyListExtractorInterface`. +These extractors are responsible of extracting the list of properties of a class. -An array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyDescriptionExtractorInterface` -must be passed as third parameter. These extractors are responsible of extracting -short and long DocBlock description of a property. +The **second argument** must be an array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyTypeExtractorInterface`. +These extractors are responsible of extracting types of a property. -Finally, an array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyAccessExtractorInterface` -must be passed as fourth parameter. These extractors are responsible of guessing -if a property is readable or writable. +The **third argument** must be an array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyDescriptionExtractorInterface`. +These extractors are responsible of extracting the DocBlock description of a +property. -The order of registration matter: the data returned will be the one returned -by the first extractor if different than ``null``. +The **fourth argument** must be an array of implementations of :class:`Symfony\\Component\\PropertyInfo\\PropertyAccessExtractorInterface`. +These extractors are responsible of guessing if a property is readable and/or +writable. +The order in which extractors are registered is important, because the returned +data will be the one returned by the first extractor which returns something +different than ``null``. -Once instantiated, the ``PropertyInfo`` class can be used to retrieve info -about properties of a class:: +Once instantiated, use the ``PropertyInfo`` class to retrieve info about any of +the properties of a class. Consider the following example class:: class MyClass { @@ -107,84 +110,94 @@ about properties of a class:: } } - var_dump($propertyInfo->getProperties('MyClass')); - var_dump($propertyInfo->getTypes('MyClass', 'foo')); - var_dump($propertyInfo->getTypes('MyClass', 'bar')); - var_dump($propertyInfo->isReadable('MyClass', 'foo')); - var_dump($propertyInfo->isReadable('MyClass', 'bar')); - var_dump($propertyInfo->isWritable('MyClass', 'foo')); - var_dump($propertyInfo->getShortDescription('MyClass', 'bar')); - var_dump($propertyInfo->getLongDescription('MyClass', 'foo')); +Given the previous ``$propertyInfo`` object, you can easily extract all the +information about any property:: - /* - Output: - array(1) { - [0] => - string(3) "foo" - } - array(1) { - [0] => - class Symfony\Component\PropertyInfo\Type#7 (6) { - private $builtinType => - string(6) "string" - private $nullable => - bool(false) - private $class => - NULL - private $collection => - bool(false) - private $collectionKeyType => - NULL - private $collectionValueType => - NULL - } - } - array(1) { - [0] => - class Symfony\Component\PropertyInfo\Type#129 (6) { - private $builtinType => - string(5) "array" - private $nullable => - bool(false) - private $class => - NULL - private $collection => - bool(true) - private $collectionKeyType => - NULL - private $collectionValueType => - NULL - } - } - bool(true) - bool(false) - bool(true) - string(17) "Virtual property." - string(37) "And here is its extended description." - */ + $properties = $propertyInfo->getProperties('MyClass'); + // $properties = array('foo') + + $barIsReadable = $propertyInfo->isReadable('MyClass', 'bar'); + // $barIsReadable = false + + $fooIsWritable = $propertyInfo->isWritable('MyClass', 'foo'); + // $fooIsWritable = true + +Extraction Methods +------------------ -As PHP doesn't support explicit type definition, ``PropertyInfo::getTypes`` -use registered extractors to an array of :class:`Symfony\\Component\\PropertyInfo\\Type` -value objects. -Those object represent complex PHP types. Refer to the API documentation -of this class for more details. +These are the public methods exposed by the API of this component: + +:method:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractorInterface::getProperties` + It returns an array with the names of all the properties exposed by the given + class: + + $result = $propertyInfo->getProperties('MyClass'); + +:method:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractorInterface::isReadable` + It returns ``true`` when the value of the given property is readable in any + way for the given class (through the property itself or through some access + method):: + + $result = $propertyInfo->isReadable('MyClass', 'foo'); + +:method:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractorInterface::isWritable` + It returns ``true`` when the value of the given property is writable in any + way for the given class (through the property itself or through some access + method): + + $result = $propertyInfo->isWritable('MyClass', 'foo'); + +:method:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractorInterface::getShortDescription` + It returns the short PHPDoc description for the given property and class (or + ``null`` if no short description is available). This short description corresponds + to the first line of the full PHPDoc description:: + + $result = $propertyInfo->getShortDescription('MyClass', 'foo'); + +:method:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractorInterface::getLongDescription` + It returns the full PHPDoc description for the given property and class (or + ``null`` if no description is available). This long description corresponds + to the full PHPDoc description except its first line:: + + $result = $propertyInfo->getLongDescription('MyClass', 'foo'); + +:method:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractorInterface::getTypes` + It returns an array of :class:`Symfony\\Component\\PropertyInfo\\Type` objects + describing the type of each property of the given class and property:: + + $result = $propertyInfo->getTypes('MyClass', 'foo'); + + Since PHP doesn't support explicit type definition, these ``Type`` objects + represent complex PHP types. Using the same ``MyClass`` class as shown above, + the content of the ``$result`` variable would be:: + + array(1) { + [0] => + class Symfony\Component\PropertyInfo\Type#7 (6) { + private $builtinType => string(6) "string" + private $nullable => bool(false) + private $class => NULL + private $collection => bool(false) + private $collectionKeyType => NULL + private $collectionValueType => NULL + } + } Extractors ---------- -Symfony is shipped with two extractors in addition to the already presented -``ReflectionExtractor`` and ``PhpDocExtractors``. -Moreover, custom extractors can be created by implementing the extractor -interfaces provided with the PropertyInfo component. +Besides the basic ``ReflectionExtractor`` and ``PhpDocExtractors`` extractors, +Symfony framework includes two additional extractors: ``ReflectionExtractor`` +and ``PhpDocExtractors``. The ``DoctrineExtractor`` ~~~~~~~~~~~~~~~~~~~~~~~~~ -The Doctrine extractor reuse metadata of the Doctrine ORM to extract the +The Doctrine extractor reuses the metadata of the Doctrine ORM to extract the list of properties and their type. It implements ``PropertyListExtractorInterface`` and ``PropertyTypeExtractorInterface`` interfaces. -Instantiate it:: +First, instantiate the extractor:: use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\Setup; @@ -198,7 +211,7 @@ Instantiate it:: $doctrineExtractor = new DoctrineExtractor($entityManager->getMetadataFactory()); -You can now use it to retrieve information about an entity mapped with Doctrine:: +Then, retrieve information about an entity mapped with Doctrine:: use Doctrine\ORM\Mapping\Column; use Doctrine\ORM\Mapping\Entity; @@ -223,29 +236,23 @@ You can now use it to retrieve information about an entity mapped with Doctrine: Output: array(1) { - [0] => - string(2) "id" + [0] => string(2) "id" } + array(1) { [0] => class Symfony\Component\PropertyInfo\Type#27 (6) { - private $builtinType => - string(3) "int" - private $nullable => - bool(false) - private $class => - NULL - private $collection => - bool(false) - private $collectionKeyType => - NULL - private $collectionValueType => - NULL + private $builtinType => string(3) "int" + private $nullable => bool(false) + private $class => NULL + private $collection => bool(false) + private $collectionKeyType => NULL + private $collectionValueType => NULL } } */ -Of course you can also register this extractor in the ``PropertyInfo`` class:: +You can also register this extractor in the ``PropertyInfo`` class:: $propertyInfo = new PropertyInfo( array($reflectionExtractor, $doctrineExtractor), @@ -258,7 +265,7 @@ The ``SerializerExtractor`` The ``SerializerExtractor`` leverages groups metadata of the Symfony Serializer Component (2.7+) to list properties having the groups passed in the context. -Instantiate it:: +First, instantiate the extractor:: use Doctrine\Common\Annotations\AnnotationReader; use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor; @@ -268,7 +275,7 @@ Instantiate it:: $serializerClassMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); $serializerExtractor = new SerializerExtractor($serializerClassMetadataFactory); -Usage:: +Then, use it to extract the information:: use Symfony\Component\Serializer\Annotation\Groups; @@ -285,8 +292,7 @@ Usage:: /* Output: array(1) { - [0] => - string(2) "bar" + [0] => string(2) "bar" } */