symfonysymfony4symfony-consolesymfony-flex

Symfony 4 - 3rd-party bundle commands are no longer automatically discovered


According to the documentation, a command class must extend Command or ContainerAwareCommand to be automatically discovered and registered (provided its bundle is registered in the Kernel, of course).

Since Symfony 4+, this discovery doesn't work as expected.

Try this:

composer create-project symfony/skeleton test-maxmind-sf4
cd test-maxmind-sf4
composer req cravler/maxmind-geoip-bundle dev-master
php bin/console list

You will notice that:

Now when I do exactly the same thing with Symfony 3, everything works properly.

composer create-project symfony/skeleton test-maxmind-sf3 ^3.0
cd test-maxmind-sf3
composer req cravler/maxmind-geoip-bundle dev-master
php bin/console list

What's missing there?

Thank you,

Ben


Solution

  • From the UPGRADE FROM to 4.0 Guide here:

    Relying on convention-based commands discovery is not supported anymore. Use PSR-4 based service discovery instead.

    Before:

    # app/config/services.yml
    services:
        # ...
    
        # implicit registration of all commands in the `Command` folder
    

    After:

    # app/config/services.yml
    services:
        # ...
    
        # explicit commands registration
        AppBundle\Command\:
            resource: '../../src/AppBundle/Command/*'
            tags: ['console.command']
    

    Hope this help