[Config] fix tracking attributes in ReflectionClassResource

This commit is contained in:
Nicolas Grekas 2021-06-09 17:56:09 +02:00
parent dd2e6059b5
commit 7ad8247422
2 changed files with 44 additions and 0 deletions

View File

@ -119,6 +119,15 @@ class ReflectionClassResource implements SelfCheckingResourceInterface
private function generateSignature(\ReflectionClass $class): iterable
{
if (\PHP_VERSION_ID >= 80000) {
$attributes = [];
foreach ($class->getAttributes() as $a) {
$attributes[] = [$a->getName(), $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
}
yield $class->getDocComment();
yield (int) $class->isFinal();
yield (int) $class->isAbstract();
@ -135,6 +144,14 @@ class ReflectionClassResource implements SelfCheckingResourceInterface
$defaults = $class->getDefaultProperties();
foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $p) {
if (\PHP_VERSION_ID >= 80000) {
foreach ($p->getAttributes() as $a) {
$attributes[] = [$a->getName(), $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
}
yield $p->getDocComment();
yield $p->isDefault() ? '<default>' : '';
yield $p->isPublic() ? 'public' : 'protected';
@ -145,9 +162,25 @@ class ReflectionClassResource implements SelfCheckingResourceInterface
}
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
if (\PHP_VERSION_ID >= 80000) {
foreach ($m->getAttributes() as $a) {
$attributes[] = [$a->getName(), $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
}
$defaults = [];
$parametersWithUndefinedConstants = [];
foreach ($m->getParameters() as $p) {
if (\PHP_VERSION_ID >= 80000) {
foreach ($p->getAttributes() as $a) {
$attributes[] = [$a->getName(), $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
}
if (!$p->isDefaultValueAvailable()) {
$defaults[$p->name] = null;

View File

@ -121,6 +121,11 @@ EOPHP;
{
yield [false, 0, "// line change\n\n"];
yield [true, 0, '/** class docblock */'];
if (\PHP_VERSION_ID >= 80000) {
yield [true, 0, '#[Foo]'];
}
yield [true, 1, 'abstract class %s'];
yield [true, 1, 'final class %s'];
yield [true, 1, 'class %s extends Exception'];
@ -140,6 +145,12 @@ EOPHP;
yield [false, 11, "public function pub(\$arg = null) {\nreturn 123;\n}"];
yield [true, 12, '/** prot docblock */'];
yield [true, 13, 'protected function prot($a = [123]) {}'];
if (\PHP_VERSION_ID >= 80000) {
yield [true, 13, '#[Foo] protected function prot($a = []) {}'];
yield [true, 13, 'protected function prot(#[Foo] $a = []) {}'];
}
yield [false, 14, '/** priv docblock */'];
yield [false, 15, ''];