From fbd2b9608818b21cbda42d8fe9379234f47f9e65 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Thu, 29 May 2025 14:00:57 +0200 Subject: [PATCH 1/3] Replace get_class() calls by ::class --- Tests/Compiler/ServiceLocatorTagPassTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Compiler/ServiceLocatorTagPassTest.php b/Tests/Compiler/ServiceLocatorTagPassTest.php index 812b47c7a..7218db6de 100644 --- a/Tests/Compiler/ServiceLocatorTagPassTest.php +++ b/Tests/Compiler/ServiceLocatorTagPassTest.php @@ -83,7 +83,7 @@ public function testProcessValue() $this->assertSame(CustomDefinition::class, $locator('bar')::class); $this->assertSame(CustomDefinition::class, $locator('baz')::class); $this->assertSame(CustomDefinition::class, $locator('some.service')::class); - $this->assertSame(CustomDefinition::class, \get_class($locator('inlines.service'))); + $this->assertSame(CustomDefinition::class, $locator('inlines.service')::class); } public function testServiceWithKeyOverwritesPreviousInheritedKey() From b511363099bce8ec9e0729e2daa406d197bf68f9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 16:08:14 +0200 Subject: [PATCH 2/3] Allow Symfony ^8.0 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 460751088..7b1e731b7 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,12 @@ "psr/container": "^1.1|^2.0", "symfony/deprecation-contracts": "^2.5|^3", "symfony/service-contracts": "^3.5", - "symfony/var-exporter": "^6.4.20|^7.2.5" + "symfony/var-exporter": "^6.4.20|^7.2.5|^8.0" }, "require-dev": { - "symfony/yaml": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0" + "symfony/yaml": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0" }, "conflict": { "ext-psr": "<1.1|>=2", From 038a6e2039f998f0d364d9ea3ae14fd0f9200ca9 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Wed, 18 Jun 2025 12:27:01 +0200 Subject: [PATCH 3/3] [DependencyInjection] Allow extending `#[AsAlias]` attribute --- Attribute/AsAlias.php | 2 +- CHANGELOG.md | 5 ++++ Loader/FileLoader.php | 2 +- .../PrototypeAsAlias/WithCustomAsAlias.php | 25 +++++++++++++++++++ Tests/Loader/FileLoaderTest.php | 3 +++ 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 Tests/Fixtures/PrototypeAsAlias/WithCustomAsAlias.php diff --git a/Attribute/AsAlias.php b/Attribute/AsAlias.php index 0839afa48..c74b0923d 100644 --- a/Attribute/AsAlias.php +++ b/Attribute/AsAlias.php @@ -17,7 +17,7 @@ * @author Alan Poulain */ #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] -final class AsAlias +class AsAlias { /** * @var list diff --git a/CHANGELOG.md b/CHANGELOG.md index df3486a9d..5c6c41cfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.4 +--- + + * Allow `#[AsAlias]` to be extended + 7.3 --- diff --git a/Loader/FileLoader.php b/Loader/FileLoader.php index bc38767bc..3cf23cf98 100644 --- a/Loader/FileLoader.php +++ b/Loader/FileLoader.php @@ -216,7 +216,7 @@ public function registerClasses(Definition $prototype, string $namespace, string } $r = $this->container->getReflectionClass($class); $defaultAlias = 1 === \count($interfaces) ? $interfaces[0] : null; - foreach ($r->getAttributes(AsAlias::class) as $attr) { + foreach ($r->getAttributes(AsAlias::class, \ReflectionAttribute::IS_INSTANCEOF) as $attr) { /** @var AsAlias $attribute */ $attribute = $attr->newInstance(); $alias = $attribute->id ?? $defaultAlias; diff --git a/Tests/Fixtures/PrototypeAsAlias/WithCustomAsAlias.php b/Tests/Fixtures/PrototypeAsAlias/WithCustomAsAlias.php new file mode 100644 index 000000000..4f1419098 --- /dev/null +++ b/Tests/Fixtures/PrototypeAsAlias/WithCustomAsAlias.php @@ -0,0 +1,25 @@ + ['PrototypeAsAlias/{WithAsAlias,AliasFooInterface}.php', [AliasFooInterface::class => new Alias(WithAsAlias::class)]]; + yield 'PrivateCustomAlias' => ['PrototypeAsAlias/{WithCustomAsAlias,AliasFooInterface}.php', [AliasFooInterface::class => new Alias(WithCustomAsAlias::class)], 'prod']; + yield 'PrivateCustomAliasNoMatch' => ['PrototypeAsAlias/{WithCustomAsAlias,AliasFooInterface}.php', [], 'dev']; yield 'Interface' => ['PrototypeAsAlias/{WithAsAliasInterface,AliasFooInterface}.php', [AliasFooInterface::class => new Alias(WithAsAliasInterface::class)]]; yield 'Multiple' => ['PrototypeAsAlias/{WithAsAliasMultiple,AliasFooInterface}.php', [ AliasFooInterface::class => new Alias(WithAsAliasMultiple::class, true),