Skip to content

Commit 7bc15b6

Browse files
[PropertyInfo] Add ConstructorExtractor documentation for 6.2 (with CPP)
1 parent addd166 commit 7bc15b6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

components/property_info.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ information from annotations of properties and methods, such as ``@var``,
438438

439439
// Extraction.php
440440
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
441+
use App\Domain\Foo;
441442

442443
$phpStanExtractor = new PhpStanExtractor();
443444
$phpStanExtractor->getTypesFromConstructor(Foo::class, 'bar');
@@ -505,6 +506,32 @@ with the ``property_info`` service in the Symfony Framework::
505506
// Type information.
506507
$doctrineExtractor->getTypes($class, $property);
507508

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

510537
Creating Your Own Extractors

0 commit comments

Comments
 (0)