Skip to content

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented May 26, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues -
License MIT

Discussion started here symfony/symfony-docs#20932 (comment)

This adds support for resolving all registered console helpers:

protected function getDefaultHelperSet(): HelperSet
{
return new HelperSet([
new FormatterHelper(),
new DebugFormatterHelper(),
new ProcessHelper(),
new QuestionHelper(),
]);
}

For example:

use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Process\Process;

#[AsCommand('app:hello')]
class AppHelloCommand
{
    public function __invoke(OutputInterface $output, ProcessHelper $helper): int
    {
        $process = new Process(['figlet', 'Symfony']);
        $helper->run($output, $process);

        // ...

        return 0;
    }
}

Improving DX, as currently alternatives include:

  • extending from the Command class and then using $this->getHelper('process')
  • defining __invoke(..., Application $application) and then using $application->getHelperSet()->get('process')

Also, all of the above alternatives lack autocompletion for the concrete helper class.

@yceruto yceruto requested a review from chalasr as a code owner May 26, 2025 22:06
@carsonbot carsonbot added this to the 7.4 milestone May 26, 2025
@yceruto yceruto added the DX DX = Developer eXperience (anything that improves the experience of using Symfony) label May 26, 2025
@yceruto
Copy link
Member Author

yceruto commented May 27, 2025

Closing this PR, as per Fabien's suggestion:

I would kill the way these helpers work. Instantiating them directly is the way to go.

and as I just realized, these helpers indeed can be initialized directly. I mistakenly assumed there were dependencies involved 🤦‍♂️ Let's update the docs accordingly.

@yceruto yceruto closed this May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Console DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants