Skip to content

[Console] Add helper resolution support for invokable commands #60555

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy