diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 5f623d894cb74..6833ea266c2aa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -59,7 +59,7 @@ use Symfony\Component\DependencyInjection\Parameter; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; -use Symfony\Component\EventDispatcher\Attribute\EventListener; +use Symfony\Component\EventDispatcher\Attribute\AsEventListener; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\Finder\Finder; @@ -555,7 +555,7 @@ public function load(array $configs, ContainerBuilder $container) $container->registerForAutoconfiguration(LoggerAwareInterface::class) ->addMethodCall('setLogger', [new Reference('logger')]); - $container->registerAttributeForAutoconfiguration(EventListener::class, static function (ChildDefinition $definition, EventListener $attribute): void { + $container->registerAttributeForAutoconfiguration(AsEventListener::class, static function (ChildDefinition $definition, AsEventListener $attribute): void { $definition->addTag('kernel.event_listener', get_object_vars($attribute)); }); diff --git a/src/Symfony/Component/Console/Attribute/ConsoleCommand.php b/src/Symfony/Component/Console/Attribute/AsCommand.php similarity index 92% rename from src/Symfony/Component/Console/Attribute/ConsoleCommand.php rename to src/Symfony/Component/Console/Attribute/AsCommand.php index 90e8c2cb137ef..b337f548f4663 100644 --- a/src/Symfony/Component/Console/Attribute/ConsoleCommand.php +++ b/src/Symfony/Component/Console/Attribute/AsCommand.php @@ -11,8 +11,11 @@ namespace Symfony\Component\Console\Attribute; +/** + * Service tag to autoconfigure commands. + */ #[\Attribute(\Attribute::TARGET_CLASS)] -class ConsoleCommand +class AsCommand { public function __construct( public string $name, diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index bdcd6f2959658..1601202e72083 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -10,7 +10,7 @@ CHANGELOG on the `console.command` tag to allow the `list` command to instantiate commands lazily * Add option `--short` to the `list` command * Add support for bright colors - * Add `ConsoleCommand` attribute for declaring commands on PHP 8 + * Add `#[AsCommand]` attribute for declaring commands on PHP 8 5.2.0 ----- diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index 8e3afcf75f59c..e35ae51ebfa28 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Console\Command; use Symfony\Component\Console\Application; -use Symfony\Component\Console\Attribute\ConsoleCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Exception\ExceptionInterface; use Symfony\Component\Console\Exception\InvalidArgumentException; use Symfony\Component\Console\Exception\LogicException; @@ -67,7 +67,7 @@ public static function getDefaultName() { $class = static::class; - if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(ConsoleCommand::class)) { + if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) { return $attribute[0]->newInstance()->name; } @@ -83,7 +83,7 @@ public static function getDefaultDescription(): ?string { $class = static::class; - if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(ConsoleCommand::class)) { + if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) { return $attribute[0]->newInstance()->description; } diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index fd6c4ba06e493..fad1f34589b96 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -13,7 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; -use Symfony\Component\Console\Attribute\ConsoleCommand; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Helper\FormatterHelper; @@ -409,7 +409,7 @@ public function testSetCodeWithStaticAnonymousFunction() /** * @requires PHP 8 */ - public function testConsoleCommandAttribute() + public function testCommandAttribute() { $this->assertSame('|foo|f', Php8Command::getDefaultName()); $this->assertSame('desc', Php8Command::getDefaultDescription()); @@ -425,7 +425,7 @@ function createClosure() }; } -#[ConsoleCommand(name: 'foo', description: 'desc', hidden: true, aliases: ['f'])] +#[AsCommand(name: 'foo', description: 'desc', hidden: true, aliases: ['f'])] class Php8Command extends Command { } diff --git a/src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php b/src/Symfony/Component/DependencyInjection/Attribute/AsTaggedItem.php similarity index 97% rename from src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php rename to src/Symfony/Component/DependencyInjection/Attribute/AsTaggedItem.php index a848e68d63516..2320336338b4c 100644 --- a/src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php +++ b/src/Symfony/Component/DependencyInjection/Attribute/AsTaggedItem.php @@ -17,7 +17,7 @@ * @author Nicolas Grekas
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
-class TaggedItem
+class AsTaggedItem
{
public function __construct(
public ?string $index = null,
diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md
index 26bc5690a22fb..a27d6f32032e5 100644
--- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md
+++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md
@@ -7,7 +7,7 @@ CHANGELOG
* Add `ServicesConfigurator::remove()` in the PHP-DSL
* Add `%env(not:...)%` processor to negate boolean values
* Add support for loading autoconfiguration rules via the `#[Autoconfigure]` and `#[AutoconfigureTag]` attributes on PHP 8
- * Add `#[TaggedItem]` attribute for defining the index and priority of classes found in tagged iterators/locators
+ * Add `#[AsTaggedItem]` attribute for defining the index and priority of classes found in tagged iterators/locators
* Add autoconfigurable attributes
* Add support for per-env configuration in loaders
* Add `ContainerBuilder::willBeAvailable()` to help with conditional configuration
diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php
index 3328274dc991e..8c4d841f5a1f8 100644
--- a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php
+++ b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php
@@ -12,7 +12,7 @@
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
-use Symfony\Component\DependencyInjection\Attribute\TaggedItem;
+use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Reference;
@@ -126,7 +126,7 @@ public static function getDefault(ContainerBuilder $container, string $serviceId
}
if ($checkTaggedItem && !$r->hasMethod($defaultMethod)) {
- foreach ($r->getAttributes(TaggedItem::class) as $attribute) {
+ foreach ($r->getAttributes(AsTaggedItem::class) as $attribute) {
return 'priority' === $indexAttribute ? $attribute->newInstance()->priority : $attribute->newInstance()->index;
}
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php
index bd3b82d64f74a..4f4b2a69468af 100644
--- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php
+++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php
@@ -13,7 +13,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
-use Symfony\Component\DependencyInjection\Attribute\TaggedItem;
+use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
@@ -235,12 +235,12 @@ public function test($tagName, ContainerBuilder $container)
}
}
-#[TaggedItem(index: 'hello', priority: 1)]
+#[AsTaggedItem(index: 'hello', priority: 1)]
class HelloNamedService extends \stdClass
{
}
-#[TaggedItem(priority: 2)]
+#[AsTaggedItem(priority: 2)]
class HelloNamedService2
{
}
diff --git a/src/Symfony/Component/EventDispatcher/Attribute/EventListener.php b/src/Symfony/Component/EventDispatcher/Attribute/AsEventListener.php
similarity index 96%
rename from src/Symfony/Component/EventDispatcher/Attribute/EventListener.php
rename to src/Symfony/Component/EventDispatcher/Attribute/AsEventListener.php
index a752673e565e1..f42d4bddd2556 100644
--- a/src/Symfony/Component/EventDispatcher/Attribute/EventListener.php
+++ b/src/Symfony/Component/EventDispatcher/Attribute/AsEventListener.php
@@ -17,7 +17,7 @@
* @author Alexander M. Turek