Search code examples
phpphpstormsymfony

PrestaSitemapBundle and multiple definition of class RouterInterface


Trying to setup PrestaSitemapBundle, but when I try to add listener an error happens.

https://github.com/prestaconcept/PrestaSitemapBundle/blob/master/Resources/doc/5-Usage-Event_Listener.md

Catchable Fatal Error: Argument 1 passed to AppBundle\EventListener\SitemapListener::__construct() must implement interface Symfony\Component\Routing\RouterInterface, array given, called in /var/www/websitename/var/cache/dev/appDevDebugProjectContainer.php on line 3268 and defined" at n/a in /var/www/websitename/src/AppBundle/EventListener/SitemapListener.php line 28

services.yml

services:
     sitemap.listener:
         class: AppBundle\EventListener\SitemapListener
         arguments:
            - ["@router"]
         tags: [{name: "presta.sitemap.listener"}]

Moreover PhpStorm shows that "multiple definition of class Routerinterface".

Is it connected with error somehow?

PhpStorm notification


Solution

  • There is an error in your service definition.

    Both..

    array:
        - 1
        - 2
    

    ..and..

    array: [1, 2]
    

    ..are ways to define a named array.

    Your service definition...

    arguments:
        - ['@router']
    

    .. is essentially creating an array with the first value being an array with '@router' as the first value of the internal array. To fix this you need to pick one of the ways to define your array. So either..

    arguments:
        - '@router'
    

    .. or ..

    arguments: ['@router']