Skip to content

Commit 06d576b

Browse files
committed
feature #18161 [PropertyInfo] Add ConstructorExtractor documentation (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [PropertyInfo] Add `ConstructorExtractor` documentation Fixes #14128 Commits ------- 8b13d33 [PropertyInfo] Add `ConstructorExtractor` documentation
2 parents 5bf60dd + 8b13d33 commit 06d576b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

components/property_info.rst

+32
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,38 @@ with the ``property_info`` service in the Symfony Framework::
479479
// Type information.
480480
$doctrineExtractor->getTypes($class, $property);
481481

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

484516
Creating Your Own Extractors

0 commit comments

Comments
 (0)