Repository navigation
Conversation
Hackwar
force-pushed
the
4.x-as-command-attribute
branch
from
November 13, 2026 00:08
5a47e9d to
ea0b105
Compare
AbstractCommand does not extend Symfony's Command, so a command written the way the Symfony 7 documentation describes, with #[AsCommand] instead of the static $defaultName removed from Symfony, had no name and could not be registered. getDefaultName() now falls back to the attribute when the class does not declare $defaultName, and the constructor applies the attribute's aliases, hidden flag, description and help. $defaultName keeps precedence. The reflection result is cached per class instead of being rebuilt on every getDefaultName() call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hackwar
force-pushed
the
4.x-as-command-attribute
branch
from
November 13, 2026 00:09
ea0b105 to
966c195
Compare
This was referenced Nov 13, 2026
Contributor
Author
|
Approved |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
AbstractCommanddoes not extend Symfony'sCommand, so Symfony's#[AsCommand]attribute was ignored: a command written the way the Symfony 7 documentation describes (the static$defaultNamewas removed from Symfony 7) had no name, andApplication::addCommand()rejected it with "The command class … does not have a name". The docs called this out as a trap.AbstractCommandnow reads the attribute:getDefaultName()returns$defaultNamewhen the class declares it (unchanged), otherwise the name from the class'#[AsCommand], without aliases or the hidden marker, so callers that build command maps fromgetDefaultName()still get a plain name;descriptionandhelpwhen they are set (helpexists on the attribute since Symfony 7.4 and is read only when present) — beforeconfigure(), so values set there still win; a name passed to the constructor takes precedence as before;$defaultName, the attribute is not inherited by subclasses;$defaultName, and its attribute) is cached per class instead of creating aReflectionPropertyon everygetDefaultName()call.$defaultNamekeeps working unchanged. Deprecating it in favour of the attribute is a separate follow-up.Testing Instructions
New tests in
tests/Command/AbstractCommandTest.phpcover name, aliases, description and help from the attribute, a hidden command, precedence of$defaultName,configure()and an explicit name, and non-inheritance (with the newtests/Fixtures/Command/AttributeCommand.php);ApplicationTest::testAddCommandNamedByAttributeregisters an attribute-only command. On4.x-devthe attribute tests fail (getDefaultName()returnsnull). Thehelptest is skipped with Symfony < 7.4 (CI's lowest-dependencies job installs 7.0).Documentation Changes Required
docs/overview.md: the "Use$defaultName, not#[AsCommand]" warning is replaced by a description of both ways to name a command, with an example and the precedence rules.docs/v3-to-v4-update.md: the note that the attribute is not read now says this applies to 4.0 and that 4.1 reads it.🤖 Generated with Claude Code