Skip to content

Commit 8b13d33

Browse files
[PropertyInfo] Add ConstructorExtractor documentation
1 parent 271e4dc commit 8b13d33

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

components/property_info.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,38 @@ with the ``property_info`` service in the Symfony Framework::
483483
// Type information.
484484
$doctrineExtractor->getTypes($class, $property);
485485

486+
ConstructorExtractor
487+
~~~~~~~~~~~~~~~~~~~~
488+
489+
The :class:`Symfony\\Component\\PropertyInfo\\Extractor\\ConstructorExtractor`
490+
tries to extract properties information by using either the
491+
:class:`Symfony\\Component\\PropertyInfo\\Extractor\\PhpStanExtractor` or
492+
the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\ReflectionExtractor`
493+
on the constructor arguments::
494+
495+
// src/Domain/Foo.php
496+
class Foo
497+
{
498+
private $bar;
499+
500+
public function __construct(string $bar)
501+
{
502+
$this->bar = $bar;
503+
}
504+
}
505+
506+
// Extraction.php
507+
use Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor;
508+
use App\Domain\Foo;
509+
510+
$constructorExtractor = new ConstructorExtractor([new ReflectionExtractor()]);
511+
$constructorExtractor->getTypes(Foo::class, 'bar')[0]->getBuiltinType(); // returns 'string'
512+
513+
.. versionadded:: 5.2
514+
515+
The :class:`Symfony\\Component\\PropertyInfo\\Extractor\\ConstructorExtractor`
516+
was introduced in Symfony 5.2.
517+
486518
.. _`components-property-information-extractors-creation`:
487519

488520
Creating Your Own Extractors

0 commit comments

Comments
 (0)