Symfony 4-不再自动发现3rd-party捆绑包命令 [英] Symfony 4 - 3rd-party bundle commands are no longer automatically discovered

查看:103
本文介绍了Symfony 4-不再自动发现3rd-party捆绑包命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档,命令类必须扩展Command或ContainerAwareCommand以自动发现并注册(当然,前提是其捆绑包已在内核中注册).

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).

自Symfony 4+起,此发现无法按预期进行.

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

尝试一下:

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

您会注意到:

  • cravler:maxmind:geoip-update未注册("cravler"命名空间下没有任何内容
  • Cravler \ MaxMindGeoIpBundle \ Command \ UpdateDatabaseCommand扩展了ContainerAwareCommand
  • 在所有环境下,config.bundles.php中都会注册Bundle Cravler \ MaxMindGeoIpBundle \ CravlerMaxMindGeoIpBundle(自动生成的配方)

现在,当我对Symfony 3进行完全相同的操作时,一切正常.

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

那里缺少什么?

谢谢

推荐答案

来自UPGRADE FROM to 4.0指南

不支持依赖基于约定的命令发现 不再.请改用基于PSR-4的服务发现.

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

之前:

# app/config/services.yml
services:
    # ...

    # implicit registration of all commands in the `Command` folder

之后:

# app/config/services.yml
services:
    # ...

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

希望获得帮助

这篇关于Symfony 4-不再自动发现3rd-party捆绑包命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆