netzding
netzding

Reputation: 777

application level error after symfony update to 3.4

today i upgraded from sf2.8 to sf3.4... first i faced some errors because i did not reworked the sf standard files, now these errors are gone and i'm stuck with an error on application level. under sf2.8 it was not an issue and tbh i dont understand why its now.

error triggered hitting "/":

[Tue Oct 02 11:37:31.885382 2018] [proxy_fcgi:error] [pid 24:tid 140202295097088] [client 172.29.0.1:37964] AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Symfony\\Component\\Debug\\Exception\\FatalThrowableError: Type error: Argument 2 passed to TheApp\\FrontendBundle\\Services\\UrlAliasService::__construct() must be an instance of TheApp\\FrontendBundle\\Routing\\Router, instance of Symfony\\Bundle\\FrameworkBundle\\Routing\\Router given, called in /var/www/var/cache/dev/ContainerV5bxhc0/appDevDebugProjectContainer.php on line 3678 in /var/www/src/TheApp/FrontendBundle/Services/UrlAliasService.php:25\nStack trace:\n#0 /var/www/var/cache/dev/ContainerV5bxhc0/appDevDebugProjectContainer.php(3678): TheApp\\FrontendBundle\\Services\\UrlAliasService->__construct(Object(Doctrine\\ORM\\EntityManager), Object(Symfony\\Bundle\\FrameworkBundle\\Routing\\Router), Object(Cocur\\Slugify\\Slugify))\n#1 /var/www/var/cache/dev/ContainerV5bxhc0/appDevDebugProjectContainer.php(3698): ContainerV5bxhc0\\appDevDebugProjectContainer->getTheApp_UrlaliasserviceService()\n#2 /var/www/var/cache/dev/ContainerV5bxhc0/appDevDebugProjectContainer.php(3872): Contain...\n'

so the service "UrlAliasService" takes 3 parameters:

...
use TheApp\FrontendBundle\Routing\Router;
...
public function __construct(EntityManager $entityManager, Router $router, Slugify $slugify)
    {
        $this->em = $entityManager;
        $this->urlRepository = $this->em->getRepository('TheAppFrontendBundle:UrlAlias');
        $this->router = $router;
        $this->slugify = $slugify;
        $this->urlAliasInProcess = new ArrayCollection();
    }

these 3 parameters get wired in services.yml:

theapp.urlaliasservice:
        class: TheApp\FrontendBundle\Services\UrlAliasService
        arguments: ["@doctrine.orm.entity_manager", "@router", "@cocur_slugify"]

here is the router class, extending BaseRouter:

namespace TheApp\FrontendBundle\Routing;

use Symfony\Bundle\FrameworkBundle\Routing\Router as BaseRouter;
...
use Symfony\Component\Routing\RequestContext;

class Router extends BaseRouter implements ContainerAwareInterface
{
    private $container;

    public function __construct(ContainerInterface $container, $resource, array $options = array(), RequestContext $context = null)
    {
        parent::__construct($container, $resource, $options, $context);
        $this->setContainer($container);
    }

    public function getGenerator()
    {
        $generator = parent::getGenerator();
        $generator->setContainer($this->container);
        return $generator;
    }

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }
}

so the error tells me that the argument passed in is from type TheApp\FrontendBundle\Routing\Router .... but it actually is from type Symfony\Bundle\FrameworkBundle\Routing\Router .... reading the code this error makes no sense right? the class TheApp\FrontendBundle\Routing\Router extends Symfony\Bundle\FrameworkBundle\Routing\Router so how can it be not an instance from it? help and explanation is very very much appreciated.

Upvotes: 0

Views: 320

Answers (1)

Denis Alimov
Denis Alimov

Reputation: 2901

it's obvious that @router is a Router service defined by Symfony\Bundle\FrameworkBundle\Routing\Router. Instead of it in arguments: ["@doctrine.orm.entity_manager", "@router", "@cocur_slugify"] you should inject your service, for example theapp.router. You have a few choices here:

  1. declare your service as theapp.route
  2. override router with your service , but I would not do it.

Upvotes: 1

Related Questions