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 2b58bd663258d..a0aeb354c74ff 100644 --- a/src/Symfony/Component/Config/Resource/ReflectionClassResource.php +++ b/src/Symfony/Component/Config/Resource/ReflectionClassResource.php @@ -119,6 +119,15 @@ private function computeHash(): string 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 @@ private function generateSignature(\ReflectionClass $class): iterable $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 @@ private function generateSignature(\ReflectionClass $class): iterable } 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 64cfbf129a990..4f61c5bbd7c61 100644 --- a/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php @@ -121,6 +121,11 @@ public function provideHashedSignature(): iterable { 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 @@ public function provideHashedSignature(): iterable 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, '']; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy