mnapoli / silly

Silly CLI micro-framework based on Symfony Console
MIT License
922 stars 52 forks source link

Get helper from classes autowired by PHP-DI #42

Open imam opened 7 years ago

imam commented 7 years ago

Currently, I can't use getHelperSet() method because I create a separate class that will be autowired by PHP-DI. So now, if I want to use getHelperSet() I have to use the old way to attach a command, by attaching a function to $app->command() second argument rather than attaching my separated class. Is there any workaround for this situation?

mnapoli commented 7 years ago

Hi, funny I got hit by that just yesterday too :/

Here is what I did:

I'd like to find a better solution too. Maybe the silly-php-di package could preconfigure the Application class? (I cannot inject the HelperSet using PHP-DI because it needs to be constructed using the Input and Output)

Another solution could be to use the SymfonyStyle class and skip helpers altogether: https://symfony.com/doc/current/console/style.html

$io = new SymfonyStyle($input, $output);
$io->ask('What is your name?');

That's simpler, though a bit hidden in Symfony's documentation.

What kind of helpers are you using?