1

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.

KitchenLee
  • 105
  • 1
  • 1
  • 6
  • This might help: https://www.tomasvotruba.cz/blog/2017/02/12/drop-all-service-tags-in-your-nette-and-symfony-applications/ – Cerad Feb 25 '17 at 23:04
  • https://stackoverflow.com/questions/55382545/implementing-strategy-pattern-symfony-4-with-compiler-pass-is-broken-for-me – Hossein Jul 21 '22 at 05:24

2 Answers2

0

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.

michail_w
  • 4,318
  • 4
  • 26
  • 43
0

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

Catalin Minovici
  • 181
  • 1
  • 13