Skip to content

Commit 378ad98

Browse files
[PropertyInfo] Add ConstructorExtractor documentation for 6.2 (with CPP)
1 parent 91bbff3 commit 378ad98

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

components/property_info.rst

+26
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ information from annotations of properties and methods, such as ``@var``,
442442

443443
// Extraction.php
444444
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
445+
use App\Domain\Foo;
445446

446447
$phpStanExtractor = new PhpStanExtractor();
447448
$phpStanExtractor->getTypesFromConstructor(Foo::class, 'bar');
@@ -509,6 +510,31 @@ with the ``property_info`` service in the Symfony Framework::
509510
// Type information.
510511
$doctrineExtractor->getTypes($class, $property);
511512

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

514540
Creating Your Own Extractors

0 commit comments

Comments
 (0)