From 7ad82474223e5951db3f9844b07a2afe8d16a9cd Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 9 Jun 2021 17:56:09 +0200 Subject: [PATCH] [Config] fix tracking attributes in ReflectionClassResource --- .../Resource/ReflectionClassResource.php | 33 +++++++++++++++++++ .../Resource/ReflectionClassResourceTest.php | 11 +++++++ 2 files changed, 44 insertions(+) diff --git a/src/Symfony/Component/Config/Resource/ReflectionClassResource.php b/src/Symfony/Component/Config/Resource/ReflectionClassResource.php index 2b58bd6632..a0aeb354c7 100644 --- a/src/Symfony/Component/Config/Resource/ReflectionClassResource.php +++ b/src/Symfony/Component/Config/Resource/ReflectionClassResource.php @@ -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() ? '' : ''; 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; diff --git a/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php index 64cfbf129a..4f61c5bbd7 100644 --- a/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php @@ -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, ''];