Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Console] Allow callable forAsCommand
,Argument
andOption
attributes arguments#61677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
An interesting option that allows the definition to be made more dynamic. Then we should probably do the same for With PHP 8.5, the named closure syntax can be used: publicfunction __invoke(SymfonyStyle$io, #[Argument(description:self::generateTheArgumentDescription(...))]string$theArgument,) |
Uh oh!
There was an error while loading.Please reload this page.
MacDada commentedSep 7, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Not required in my codebase, but should be simple enough -> I can volunteer a new PR or extend this one if this is the way to go :-) |
publicstring$name ='', | ||
array|callable$suggestedValues = [], | ||
) { | ||
$this->description =\is_callable($description) ?$description() :$description; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I would apply the same approach we used for suggestedValues, so that non-static callables are supported. This way, we can access the$this
instance and its dependencies if needed, for example, to build a description dynamically based on the command's dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
already tried that and failed, not sure why, guessingarray|callable
(working as getting "in" as just array) vsstring|callable
(not working, as not getting in as array is not a string, and not an acceptable callable)
will try doing it again tomorrow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Alright, I've tried to do that, but I've noticed a problem: I don't think I can do that without breaking compatibility.
As for now,$description
is apublic string
field:https://github.com/symfony/symfony/blob/v7.3.4/src/Symfony/Component/Console/Attribute/Argument.php#L39
I'd have to change it topublic string|\Closure
, so if someone's code relies upon$description
being a string, it would break it.
What's the use case? I prefer simple static data. A static call can only return static data anyway. |
MacDada commentedSep 8, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
publicstaticfunctiongenerateEducationDescription():string | ||
{ | ||
returnsprintf('Mention your favourite lectures from %s!',self::UNIVERSITY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
let's inline this, indirections makes reviewing test cases more complex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
i guess u meant to inline the const:71a08ac
@MacDada any chance you can finish this one soon? The feature freeze period is starting for 7.4. |
Uh oh!
There was an error while loading.Please reload this page.
…ute`s being interpreted as callablesymfony#61677 (comment)
MacDada commentedSep 29, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@chalasr As for my own particular needs – this PR is finished. BUT:
|
MacDada commentedSep 29, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@GromNaN I've done it for I didn't do it for |
a98e93d
to6b89c2c
Compare…on`'s `Attribute`s.
…ute`s being interpreted as callablesymfony#61677 (comment)
6b89c2c
tof85c1ad
Comparef85c1ad
to8929999
Compare$description
ofArgument
's andOption
'sAttribute
sAsCommand
,Argument
andOption
attributes8929999
to5fd1f25
CompareAsCommand
,Argument
andOption
attributesAsCommand
,Argument
andOption
attributes arguments
Given:
With "old style" Commands I'm able to generate description of an Argument:
It's currently not possible with "Symfony Style":
It becomes possible with this PR: