How to avoid "knp_menu.factory" deprecation?

537 Views Asked by At

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

There are 1 best solutions below

0
On BEST ANSWER

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.