I just want to know how to get all my commands Symfony services into my compiler pass ?
Is there a mean to find services by implemented interfaces ? Or perhaps i have to tag them all ?
Thanks, KL.
I just want to know how to get all my commands Symfony services into my compiler pass ?
Is there a mean to find services by implemented interfaces ? Or perhaps i have to tag them all ?
Thanks, KL.
You should tag them all. There is no way to retreive services which are instance of some expected class/interface.
Anyway, you can just get all, iterate over them, and filter only those which extends your interface. But it's much slower, and the most awful way to do it.
I hope I understood you question correctly. If you're trying to get all commands defined in your application then:
$kernel = $this->container->get('kernel');
$application = new Application($kernel);
$commands = $application->all('doctrine');
var_dump($commands);die;
This example with a fresh symfony install you can fetch all doctrine commands. Just replace 'doctrine' with your commands prefix.
Take a look in \Symfony\Bundle\FrameworkBundle\Console\Application especially registerCommands method. I'm using latest version Symfony 3.2.4