Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

[Console] Add support forSignalableCommandInterface with invokable commands#60389

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

Merged
chalasr merged 1 commit intosymfony:7.3fromHypeMC:invokable-signalable-command
May 9, 2025

Conversation

HypeMC
Copy link
Member

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
Issues-
LicenseMIT

Currently, it's not possible to use theSignalableCommandInterface with invokable commands.
This PR adds support for that.

#[AsCommand(name:'app:example')]class ExampleCommandimplements SignalableCommandInterface{publicfunction__invoke(InputInterface$input,OutputInterface$output):int    {// ...return Command::SUCCESS;    }publicfunctiongetSubscribedSignals():array    {return [\SIGINT, \SIGTERM];    }publicfunctionhandleSignal(int$signal,int|false$previousExitCode =0):int|false    {// handle signalreturn0;    }}

@HypeMCHypeMCforce-pushed theinvokable-signalable-command branch from9767999 toae770b7CompareMay 9, 2025 12:10
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Some minor CS fixes and GTM, thanks.

@nicolas-grekasnicolas-grekas added the ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelMay 9, 2025
@yceruto
Copy link
Member

I believe there’s another way to keep this working without implementing the interface:https://github.com/symfony/symfony-docs/pull/20932/files#diff-738612fa300cdcb8d044a240dcec7bc9db05a1671f30e3d1b987bbf200037b8c but I might be missing something, could you please confirm?

@nicolas-grekas
Copy link
Member

@yceruto it should work indeed, but the proposed approach makes sense to me also.

@chalasr
Copy link
Member

@yceruto I remember we discussed this at the time and you had some arguments againstSignalableCommandInterface, namely that the listener approach is better design-wise because less intrusive. I agreed with that and still do but I think either we decide that we don't need this interface at all and then it should be deprecated, or invokable commands should support it

@yceruto
Copy link
Member

Yes, I'd prefer a single way to do this for invokable command, less variants to document and maintain.

@HypeMCHypeMCforce-pushed theinvokable-signalable-command branch fromae770b7 tobb97a2aCompareMay 9, 2025 13:05
@HypeMC
Copy link
MemberAuthor

@yceruto Just a heads up,symfony/event-dispatcher is an optional dependency of the console component. If not installed, users won't be able to handle signals. I'm not saying that's good or bad, just something to be aware of.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this very issue/PR shows that this style would be expected to work. It might also make the feature easier to use when the component is used standalone.

@yceruto
Copy link
Member

I understand the intention of supporting all features used in normal commands, but in standalone usage, the invokable command approach doesn’t work naturally, people need to call explicitly setCode(), name, description, etc. In those cases, you’ll probably extend theCommand class directly to avoid the extra burden.

GromNaN and chalasr reacted with thumbs up emoji

Copy link
Member

@chalasrchalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

for the sake of feature parity between invokable and non-invokable commands

@HypeMC
Copy link
MemberAuthor

My argument was more about why not to deprecate or remove theSignalableCommandInterface and since it has its use case (when the component is used standalone), it feels counter-intuitive for it not to work with invokable commands.

@yceruto
Copy link
Member

In those standalone cases without anevent-dispatcher, you can still use signalable invokable commands by extendingCommand and implementingSignalableCommandInterface. The additional requirement is the manual extension, which is fine in my opinion since these are edge cases.

@yceruto
Copy link
Member

If the goal is to simplify support for invokable commands, I suggest keeping this PR as-is with theCommand implements SignalableCommandInterface approach part only. This way, if someone wants to use this feature with an invokable command, they only need to extend theCommand class, just as we currently recommend forinteract() and other advanced use cases.

@chalasr
Copy link
Member

chalasr commentedMay 9, 2025
edited
Loading

@yceruto If you mean we should not supportSomeInvokableCommand implements SignalableCommandInterface then I disagree, reducing differences/limitations using invokable commands is worthwhile IMHO. The fact that extendingCommand is easier with console standalone shouldn't be taken as given I think, might improves later. Addinginteract() orinitialize() equivalents at some point is not excluded to me, if there's some traction.

@yceruto
Copy link
Member

I’m fine with invokable commands not supporting all CLI features out of the box. If extending the Command class is the way to enable them, that’s totally acceptable to me, just like we already do with invokable controllers and AbstractController. I don’t mind extending a class if that’s all it takes to unlock the functionality I need.

@nicolas-grekas
Copy link
Member

Sure, but why make it more complex than expected? I don't see your point sorry.

@chalasr
Copy link
Member

Shortcut methods and unsupported features are different stories. Stop me if I'm wrong but there is no AbstractController feature that cannot be implemented the same way by controllers not extending it

@yceruto
Copy link
Member

My goal is to make it simpler for developers, but I’m probably wrong in this case, sorry for the noise and confusion@nicolas-grekas.

@nicolas-grekas
Copy link
Member

No worries, it's always useful to have a discussion. Here I don't see much added complexity (I see this as simpler actually, on the Command side) so I'm fine with the change.

@chalasr
Copy link
Member

Thank you@HypeMC.

HypeMC reacted with hooray emoji

@chalasrchalasr merged commit00a39e7 intosymfony:7.3May 9, 2025
10 of 11 checks passed
@HypeMCHypeMC deleted the invokable-signalable-command branchMay 9, 2025 14:48
@fabpotfabpot mentioned this pull requestMay 10, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@chalasrchalasrchalasr approved these changes

Assignees
No one assigned
Labels
ConsoleFeature❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze"Status: Reviewed
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

5 participants
@HypeMC@yceruto@nicolas-grekas@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp