Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fa07c6

Browse files
committed
bug #41644 [Config] fix tracking attributes in ReflectionClassResource (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [Config] fix tracking attributes in ReflectionClassResource | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #39988 | License | MIT | Doc PR | - Commits ------- 7ad8247 [Config] fix tracking attributes in ReflectionClassResource
2 parents dd2e605 + 7ad8247 commit 0fa07c6

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/Symfony/Component/Config/Resource/ReflectionClassResource.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ private function computeHash(): string
119119

120120
private function generateSignature(\ReflectionClass $class): iterable
121121
{
122+
if (\PHP_VERSION_ID >= 80000) {
123+
$attributes = [];
124+
foreach ($class->getAttributes() as $a) {
125+
$attributes[] = [$a->getName(), $a->getArguments()];
126+
}
127+
yield print_r($attributes, true);
128+
$attributes = [];
129+
}
130+
122131
yield $class->getDocComment();
123132
yield (int) $class->isFinal();
124133
yield (int) $class->isAbstract();
@@ -135,6 +144,14 @@ private function generateSignature(\ReflectionClass $class): iterable
135144
$defaults = $class->getDefaultProperties();
136145

137146
foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $p) {
147+
if (\PHP_VERSION_ID >= 80000) {
148+
foreach ($p->getAttributes() as $a) {
149+
$attributes[] = [$a->getName(), $a->getArguments()];
150+
}
151+
yield print_r($attributes, true);
152+
$attributes = [];
153+
}
154+
138155
yield $p->getDocComment();
139156
yield $p->isDefault() ? '<default>' : '';
140157
yield $p->isPublic() ? 'public' : 'protected';
@@ -145,9 +162,25 @@ private function generateSignature(\ReflectionClass $class): iterable
145162
}
146163

147164
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
165+
if (\PHP_VERSION_ID >= 80000) {
166+
foreach ($m->getAttributes() as $a) {
167+
$attributes[] = [$a->getName(), $a->getArguments()];
168+
}
169+
yield print_r($attributes, true);
170+
$attributes = [];
171+
}
172+
148173
$defaults = [];
149174
$parametersWithUndefinedConstants = [];
150175
foreach ($m->getParameters() as $p) {
176+
if (\PHP_VERSION_ID >= 80000) {
177+
foreach ($p->getAttributes() as $a) {
178+
$attributes[] = [$a->getName(), $a->getArguments()];
179+
}
180+
yield print_r($attributes, true);
181+
$attributes = [];
182+
}
183+
151184
if (!$p->isDefaultValueAvailable()) {
152185
$defaults[$p->name] = null;
153186

src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ public function provideHashedSignature(): iterable
121121
{
122122
yield [false, 0, "// line change\n\n"];
123123
yield [true, 0, '/** class docblock */'];
124+
125+
if (\PHP_VERSION_ID >= 80000) {
126+
yield [true, 0, '#[Foo]'];
127+
}
128+
124129
yield [true, 1, 'abstract class %s'];
125130
yield [true, 1, 'final class %s'];
126131
yield [true, 1, 'class %s extends Exception'];
@@ -140,6 +145,12 @@ public function provideHashedSignature(): iterable
140145
yield [false, 11, "public function pub(\$arg = null) {\nreturn 123;\n}"];
141146
yield [true, 12, '/** prot docblock */'];
142147
yield [true, 13, 'protected function prot($a = [123]) {}'];
148+
149+
if (\PHP_VERSION_ID >= 80000) {
150+
yield [true, 13, '#[Foo] protected function prot($a = []) {}'];
151+
yield [true, 13, 'protected function prot(#[Foo] $a = []) {}'];
152+
}
153+
143154
yield [false, 14, '/** priv docblock */'];
144155
yield [false, 15, ''];
145156

0 commit comments

Comments
 (0)