Skip to content

Commit 7807e9b

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: [PropertyInfo] Add `ConstructorExtractor` documentation
2 parents 655fbe0 + 06d576b commit 7807e9b

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
@@ -505,6 +505,38 @@ with the ``property_info`` service in the Symfony Framework::
505505
// Type information.
506506
$doctrineExtractor->getTypes($class, $property);
507507

508+
ConstructorExtractor
509+
~~~~~~~~~~~~~~~~~~~~
510+
511+
The :class:`Symfony\\Component\\PropertyInfo\\Extractor\\ConstructorExtractor`
512+
tries to extract properties information by using either the
513+
:class:`Symfony\\Component\\PropertyInfo\\Extractor\\PhpStanExtractor` or
514+
the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\ReflectionExtractor`
515+
on the constructor arguments::
516+
517+
// src/Domain/Foo.php
518+
class Foo
519+
{
520+
private $bar;
521+
522+
public function __construct(string $bar)
523+
{
524+
$this->bar = $bar;
525+
}
526+
}
527+
528+
// Extraction.php
529+
use Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor;
530+
use App\Domain\Foo;
531+
532+
$constructorExtractor = new ConstructorExtractor([new ReflectionExtractor()]);
533+
$constructorExtractor->getTypes(Foo::class, 'bar')[0]->getBuiltinType(); // returns 'string'
534+
535+
.. versionadded:: 5.2
536+
537+
The :class:`Symfony\\Component\\PropertyInfo\\Extractor\\ConstructorExtractor`
538+
was introduced in Symfony 5.2.
539+
508540
.. _`components-property-information-extractors-creation`:
509541

510542
Creating Your Own Extractors

0 commit comments

Comments
 (0)