<?php
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
class Foo
{
/**
* Contains integer, but var-annotation claims
* it's a string collection.
*
* @var string[]
*/
public $foo = 1;
/**
* bar is awesome.
*
* Because bar contains all the awesome stuff.
*
* @var object
*/
private $bar;
/**
* @var int
*/
protected $baz;
}
$listExtractor = $typeExtractor =
$accessExtractor = new ReflectionExtractor();
$descriptionExtractor = $typeExtractor2 = new PhpDocExtractor();
$propertyInfo = new PropertyInfoExtractor(
[$listExtractor],
[$typeExtractor, $typeExtractor2],
[$descriptionExtractor],
[$accessExtractor]
);
dump(
$propertyInfo->getProperties(Foo::class),
$propertyInfo->getTypes(Foo::class, 'foo'),
$propertyInfo->getTypes(Foo::class, 'bar'),
$propertyInfo->getShortDescription(Foo::class, 'bar'),
$propertyInfo->getLongDescription(Foo::class, 'bar'),
$propertyInfo->isReadable(Foo::class, 'baz')
);
^ array:1 [
0 => "foo"
]
^ array:1 [
0 => Symfony\Component\PropertyInfo\Type {#1402
-builtinType: "int"
-nullable: false
-class: null
-collection: false
-collectionKeyType: null
-collectionValueType: null
}
]
^ array:1 [
0 => Symfony\Component\PropertyInfo\Type {#1404
-builtinType: "object"
-nullable: false
-class: null
-collection: false
-collectionKeyType: null
-collectionValueType: null
}
]
^ "bar is awesome."
^ "Because bar contains all the awesome stuff."
^ false