Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 45b53fe

Browse filesBrowse files
feature #40556 Add #[As-prefix] to service attributes (nicolas-grekas)
This PR was merged into the 5.3-dev branch. Discussion ---------- Add `#[As-prefix]` to service attributes | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - This PR renames all existing attributes with the `As` prefix, as I proposed several times already. This should help autocompletion, and it's required to not collide with existing class names (eg the `Command` class, but also the old `Controller` class, etc.) I think this `As` prefix is a convention for the better. Commits ------- 4f13189 Add `#[As-prefix]` to service attributes
2 parents ea58a15 + 4f13189 commit 45b53fe
Copy full SHA for 45b53fe

File tree

14 files changed

+31
-28
lines changed
Filter options

14 files changed

+31
-28
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
use Symfony\Component\DependencyInjection\Parameter;
6060
use Symfony\Component\DependencyInjection\Reference;
6161
use Symfony\Component\DependencyInjection\ServiceLocator;
62-
use Symfony\Component\EventDispatcher\Attribute\EventListener;
62+
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
6363
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6464
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
6565
use Symfony\Component\Finder\Finder;
@@ -556,7 +556,7 @@ public function load(array $configs, ContainerBuilder $container)
556556
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
557557
->addMethodCall('setLogger', [new Reference('logger')]);
558558

559-
$container->registerAttributeForAutoconfiguration(EventListener::class, static function (ChildDefinition $definition, EventListener $attribute): void {
559+
$container->registerAttributeForAutoconfiguration(AsEventListener::class, static function (ChildDefinition $definition, AsEventListener $attribute): void {
560560
$definition->addTag('kernel.event_listener', get_object_vars($attribute));
561561
});
562562
$container->registerAttributeForAutoconfiguration(AsController::class, static function (ChildDefinition $definition, AsController $attribute): void {

‎src/Symfony/Component/Console/Attribute/ConsoleCommand.php renamed to ‎src/Symfony/Component/Console/Attribute/AsCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Attribute/AsCommand.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111

1212
namespace Symfony\Component\Console\Attribute;
1313

14+
/**
15+
* Service tag to autoconfigure commands.
16+
*/
1417
#[\Attribute(\Attribute::TARGET_CLASS)]
15-
class ConsoleCommand
18+
class AsCommand
1619
{
1720
public function __construct(
1821
public string $name,

‎src/Symfony/Component/Console/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CHANGELOG
1010
on the `console.command` tag to allow the `list` command to instantiate commands lazily
1111
* Add option `--short` to the `list` command
1212
* Add support for bright colors
13-
* Add `ConsoleCommand` attribute for declaring commands on PHP 8
13+
* Add `#[AsCommand]` attribute for declaring commands on PHP 8
1414

1515
5.2.0
1616
-----

‎src/Symfony/Component/Console/Command/Command.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Command/Command.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Console\Command;
1313

1414
use Symfony\Component\Console\Application;
15-
use Symfony\Component\Console\Attribute\ConsoleCommand;
15+
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Exception\ExceptionInterface;
1717
use Symfony\Component\Console\Exception\InvalidArgumentException;
1818
use Symfony\Component\Console\Exception\LogicException;
@@ -67,7 +67,7 @@ public static function getDefaultName()
6767
{
6868
$class = static::class;
6969

70-
if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(ConsoleCommand::class)) {
70+
if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) {
7171
return $attribute[0]->newInstance()->name;
7272
}
7373

@@ -83,7 +83,7 @@ public static function getDefaultDescription(): ?string
8383
{
8484
$class = static::class;
8585

86-
if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(ConsoleCommand::class)) {
86+
if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) {
8787
return $attribute[0]->newInstance()->description;
8888
}
8989

‎src/Symfony/Component/Console/Tests/Command/CommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Command/CommandTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Application;
16-
use Symfony\Component\Console\Attribute\ConsoleCommand;
16+
use Symfony\Component\Console\Attribute\AsCommand;
1717
use Symfony\Component\Console\Command\Command;
1818
use Symfony\Component\Console\Exception\InvalidOptionException;
1919
use Symfony\Component\Console\Helper\FormatterHelper;
@@ -409,7 +409,7 @@ public function testSetCodeWithStaticAnonymousFunction()
409409
/**
410410
* @requires PHP 8
411411
*/
412-
public function testConsoleCommandAttribute()
412+
public function testCommandAttribute()
413413
{
414414
$this->assertSame('|foo|f', Php8Command::getDefaultName());
415415
$this->assertSame('desc', Php8Command::getDefaultDescription());
@@ -425,7 +425,7 @@ function createClosure()
425425
};
426426
}
427427

428-
#[ConsoleCommand(name: 'foo', description: 'desc', hidden: true, aliases: ['f'])]
428+
#[AsCommand(name: 'foo', description: 'desc', hidden: true, aliases: ['f'])]
429429
class Php8Command extends Command
430430
{
431431
}

‎src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php renamed to ‎src/Symfony/Component/DependencyInjection/Attribute/AsTaggedItem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Attribute/AsTaggedItem.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @author Nicolas Grekas <p@tchwork.com>
1818
*/
1919
#[\Attribute(\Attribute::TARGET_CLASS)]
20-
class TaggedItem
20+
class AsTaggedItem
2121
{
2222
public function __construct(
2323
public ?string $index = null,

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CHANGELOG
77
* Add `ServicesConfigurator::remove()` in the PHP-DSL
88
* Add `%env(not:...)%` processor to negate boolean values
99
* Add support for loading autoconfiguration rules via the `#[Autoconfigure]` and `#[AutoconfigureTag]` attributes on PHP 8
10-
* Add `#[TaggedItem]` attribute for defining the index and priority of classes found in tagged iterators/locators
10+
* Add `#[AsTaggedItem]` attribute for defining the index and priority of classes found in tagged iterators/locators
1111
* Add autoconfigurable attributes
1212
* Add support for per-env configuration in loaders
1313
* Add `ContainerBuilder::willBeAvailable()` to help with conditional configuration

‎src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
15-
use Symfony\Component\DependencyInjection\Attribute\TaggedItem;
15+
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1818
use Symfony\Component\DependencyInjection\Reference;
@@ -126,7 +126,7 @@ public static function getDefault(ContainerBuilder $container, string $serviceId
126126
}
127127

128128
if ($checkTaggedItem && !$r->hasMethod($defaultMethod)) {
129-
foreach ($r->getAttributes(TaggedItem::class) as $attribute) {
129+
foreach ($r->getAttributes(AsTaggedItem::class) as $attribute) {
130130
return 'priority' === $indexAttribute ? $attribute->newInstance()->priority : $attribute->newInstance()->index;
131131
}
132132

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
16-
use Symfony\Component\DependencyInjection\Attribute\TaggedItem;
16+
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
1717
use Symfony\Component\DependencyInjection\ChildDefinition;
1818
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
1919
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
@@ -235,12 +235,12 @@ public function test($tagName, ContainerBuilder $container)
235235
}
236236
}
237237

238-
#[TaggedItem(index: 'hello', priority: 1)]
238+
#[AsTaggedItem(index: 'hello', priority: 1)]
239239
class HelloNamedService extends \stdClass
240240
{
241241
}
242242

243-
#[TaggedItem(priority: 2)]
243+
#[AsTaggedItem(priority: 2)]
244244
class HelloNamedService2
245245
{
246246
}

‎src/Symfony/Component/EventDispatcher/Attribute/EventListener.php renamed to ‎src/Symfony/Component/EventDispatcher/Attribute/AsEventListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/EventDispatcher/Attribute/AsEventListener.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @author Alexander M. Turek <me@derrabus.de>
1818
*/
1919
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
20-
class EventListener
20+
class AsEventListener
2121
{
2222
public function __construct(
2323
public ?string $event = null,

‎src/Symfony/Component/EventDispatcher/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/EventDispatcher/CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CHANGELOG
44
5.3
55
---
66

7-
* Add `EventListener` attribute for declaring listeners on PHP 8
7+
* Add `#[AsEventListener]` attribute for declaring listeners on PHP 8
88

99
5.1.0
1010
-----

‎src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/EventDispatcher/Tests/DependencyInjection/RegisterListenersPassTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
2121
use Symfony\Component\DependencyInjection\Reference;
22-
use Symfony\Component\EventDispatcher\Attribute\EventListener;
22+
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
2323
use Symfony\Component\EventDispatcher\DependencyInjection\AddEventAliasesPass;
2424
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
2525
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -248,7 +248,7 @@ public function testTaggedInvokableEventListener()
248248
}
249249

250250
$container = new ContainerBuilder();
251-
$container->registerAttributeForAutoconfiguration(EventListener::class, static function (ChildDefinition $definition, EventListener $attribute): void {
251+
$container->registerAttributeForAutoconfiguration(AsEventListener::class, static function (ChildDefinition $definition, AsEventListener $attribute): void {
252252
$definition->addTag('kernel.event_listener', get_object_vars($attribute));
253253
});
254254
$container->register('foo', TaggedInvokableListener::class)->setAutoconfigured(true);
@@ -282,7 +282,7 @@ public function testTaggedMultiEventListener()
282282
}
283283

284284
$container = new ContainerBuilder();
285-
$container->registerAttributeForAutoconfiguration(EventListener::class, static function (ChildDefinition $definition, EventListener $attribute): void {
285+
$container->registerAttributeForAutoconfiguration(AsEventListener::class, static function (ChildDefinition $definition, AsEventListener $attribute): void {
286286
$definition->addTag('kernel.event_listener', get_object_vars($attribute));
287287
});
288288
$container->register('foo', TaggedMultiListener::class)->setAutoconfigured(true);

‎src/Symfony/Component/EventDispatcher/Tests/Fixtures/TaggedInvokableListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/EventDispatcher/Tests/Fixtures/TaggedInvokableListener.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
namespace Symfony\Component\EventDispatcher\Tests\Fixtures;
1313

14-
use Symfony\Component\EventDispatcher\Attribute\EventListener;
14+
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
1515

16-
#[EventListener]
16+
#[AsEventListener]
1717
final class TaggedInvokableListener
1818
{
1919
public function __invoke(CustomEvent $event): void

‎src/Symfony/Component/EventDispatcher/Tests/Fixtures/TaggedMultiListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/EventDispatcher/Tests/Fixtures/TaggedMultiListener.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
namespace Symfony\Component\EventDispatcher\Tests\Fixtures;
1313

14-
use Symfony\Component\EventDispatcher\Attribute\EventListener;
14+
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
1515

16-
#[EventListener(event: CustomEvent::class, method: 'onCustomEvent')]
17-
#[EventListener(event: 'foo', priority: 42)]
18-
#[EventListener(event: 'bar', method: 'onBarEvent')]
16+
#[AsEventListener(event: CustomEvent::class, method: 'onCustomEvent')]
17+
#[AsEventListener(event: 'foo', priority: 42)]
18+
#[AsEventListener(event: 'bar', method: 'onBarEvent')]
1919
final class TaggedMultiListener
2020
{
2121
public function onCustomEvent(CustomEvent $event): void

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.