How to avoid “knp_menu.factory” deprecation?

狂风中的少年 提交于 2020-01-07 04:41:08

问题


I'm trying to use KNPMenuBundle with Sumfony 3.3 but I'm getting this annoying warning:

Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. You should rename (or alias) the "knp_menu.factory" service to "Knp\Menu\FactoryInterface" instead.

Trace: {..../vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php:344: }

I did not set this knp_menu.factory at all, probably it was automatically set by the bundle.

Do I need to configure anything to make this warning go away?


回答1:


I resolved it like this:

app.component_menu.builder:
    class: AppBundle\Component\Menu\Builder
    arguments: ['@knp_menu.factory', '@event_dispatcher']
    calls:
        - [setAuthorizationChecker, ['@security.authorization_checker']]


Knp\Menu\ItemInterface:
    class: Knp\Menu\MenuItem
    factory: ['@app.component_menu.builder', mainMenu]
    arguments: ['@knp_menu.matcher']
    tags:
        - { name: knp_menu.menu, alias: main }

Knp\Menu\FactoryInterface:
    alias: knp_menu.factory
    public: false

Not sure if this is the recommended resolution, but it removes the deprecation notices.



来源:https://stackoverflow.com/questions/44922522/how-to-avoid-knp-menu-factory-deprecation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!