Skip to content

Commit

Permalink
Merge branch '4.4' into 5.3
Browse files Browse the repository at this point in the history
* 4.4:
  [Config] Fix signature generation with nested attributes on PHP 8.1
  [Cache] allow/provide psr/simple-cache v2
  [Validator] Add missing translations for Slovenian (sl)
  Add missing translations for Bosnian (bs)
  Bump Symfony version to 4.4.34
  Update VERSION for 4.4.33
  Update CONTRIBUTORS for 4.4.33
  Update CHANGELOG for 4.4.33
  • Loading branch information
nicolas-grekas committed Oct 29, 2021
2 parents ac23c2f + e99b65a commit f080af0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
14 changes: 10 additions & 4 deletions Resource/ReflectionClassResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private function generateSignature(\ReflectionClass $class): iterable
if (\PHP_VERSION_ID >= 80000) {
$attributes = [];
foreach ($class->getAttributes() as $a) {
$attributes[] = [$a->getName(), $a->getArguments()];
$attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
Expand All @@ -148,7 +148,7 @@ private function generateSignature(\ReflectionClass $class): iterable
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()];
$attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
Expand All @@ -168,7 +168,7 @@ 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()];
$attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
Expand All @@ -179,7 +179,7 @@ private function generateSignature(\ReflectionClass $class): iterable
foreach ($m->getParameters() as $p) {
if (\PHP_VERSION_ID >= 80000) {
foreach ($p->getAttributes() as $a) {
$attributes[] = [$a->getName(), $a->getArguments()];
$attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()];
}
yield print_r($attributes, true);
$attributes = [];
Expand All @@ -191,6 +191,12 @@ private function generateSignature(\ReflectionClass $class): iterable
continue;
}

if (\PHP_VERSION_ID >= 80100) {
$defaults[$p->name] = (string) $p;

continue;
}

if (!$p->isDefaultValueConstant() || $defined($p->getDefaultValueConstantName())) {
$defaults[$p->name] = $p->getDefaultValue();

Expand Down
22 changes: 21 additions & 1 deletion Tests/Resource/ReflectionClassResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public function provideHashedSignature(): iterable
yield [true, 0, '#[Foo]'];
}

if (\PHP_VERSION_ID >= 80100) {
yield [true, 0, '#[Foo(new MissingClass)]'];
}

yield [true, 1, 'abstract class %s'];
yield [true, 1, 'final class %s'];
yield [true, 1, 'class %s extends Exception'];
Expand All @@ -135,6 +139,11 @@ public function provideHashedSignature(): iterable
yield [true, 4, '/** pub docblock */'];
yield [true, 5, 'protected $pub = [];'];
yield [true, 5, 'public $pub = [123];'];

if (\PHP_VERSION_ID >= 80100) {
yield [true, 5, '#[Foo(new MissingClass)] public $pub = [];'];
}

yield [true, 6, '/** prot docblock */'];
yield [true, 7, 'private $prot;'];
yield [false, 8, '/** priv docblock */'];
Expand All @@ -151,6 +160,11 @@ public function provideHashedSignature(): iterable
yield [true, 13, 'protected function prot(#[Foo] $a = []) {}'];
}

if (\PHP_VERSION_ID >= 80100) {
yield [true, 13, '#[Foo(new MissingClass)] protected function prot($a = []) {}'];
yield [true, 13, 'protected function prot(#[Foo(new MissingClass)] $a = []) {}'];
}

yield [false, 14, '/** priv docblock */'];
yield [false, 15, ''];

Expand All @@ -162,10 +176,16 @@ public function provideHashedSignature(): iterable
yield [false, 9, 'private string $priv;'];
}

if (\PHP_VERSION_ID >= 80100) {
yield [true, 17, 'public function __construct(private $bar = new \stdClass()) {}'];
yield [true, 17, 'public function ccc($bar = new \stdClass()) {}'];
yield [true, 17, 'public function ccc($bar = new MissingClass()) {}'];
}

yield [true, 17, 'public function ccc($bar = 187) {}'];
yield [true, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}'];
yield [true, 17, 'public function ccc($bar = parent::BOOM) {}'];
yield [true, 17, null, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }];
yield [\PHP_VERSION_ID < 80100, 17, null, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }];
}

public function testEventSubscriber()
Expand Down

0 comments on commit f080af0

Please sign in to comment.