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

Using SymfonyStyle with Helpers#61025

Discussion options

With the new#[AsCommand] style of writing CLI commands, it's convenient to injectSymfonyStyle directly, but what's a bit annoying is most helpers still takeInputInterface andOutputInterface, e.g.https://symfony.com/doc/current/components/console/helpers/questionhelper.html$helper->ask($input, $output, $question)

This means that for cases where we use helpers but still want to use SymfonyStyle for other things, we have to do this, which feels gross:

publicfunction __invoke(SymfonyStyle$io,InputInterface$input,OutputInterface$output,        #[Argument('Some name')]string$name,    ):int {

That leads me to ask, shouldn't there be a way to get the$input and$output from SymfonyStyle (aka$io)? So we could only manage one dependency but then pass in$io->getInput(), $io->getOutput() to helpers, or even better if we could have a variant of the helpers that takes$io instead.

You must be logged in to vote

Ah right, forgot$style->askQuestion() is a thing, so that helps with that case. Also for TreeHelperSymfonyStyle is anOutputInterface so it can be passed in to most output-only helpers. Also there'sInputAwareInterface that helpers can have to get it filled in I guess. So I guess it's fine as-is.

Replies: 1 comment

Comment options

Ah right, forgot$style->askQuestion() is a thing, so that helps with that case. Also for TreeHelperSymfonyStyle is anOutputInterface so it can be passed in to most output-only helpers. Also there'sInputAwareInterface that helpers can have to get it filled in I guess. So I guess it's fine as-is.

You must be logged in to vote
0 replies
Answer selected byfrancislavoie
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@francislavoie

[8]ページ先頭

©2009-2025 Movatter.jp