schmittjoh / JMSI18nRoutingBundle

Allows you to internationalize your routing
http://jmsyst.com/bundles/JMSI18nRoutingBundle
358 stars 159 forks source link

User Deprecated: The "router" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0 #216

Closed edurenye closed 6 years ago

edurenye commented 6 years ago

I got the following deprecation after updating to Symfony 3.4:

User Deprecated: The "router" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead.

Error:

"exception" => ErrorException {#2303 ▼

message: "User Deprecated: The "router" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead."

code: 0

file: "vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php"

line: 275

severity: E_USER_DEPRECATED

trace: {▼ vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:275 {▶} vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php:85 {▶} src/AppBundle/Controller/Backend/DashboardController.php:16 {▼ › ->setPageTitle('Dashboard') › ->addBreadcrumb('Dashboard', $this->generateUrl('backend.dashboard'), 'dashboard') › ; } AppBundle\Controller\Backend\DashboardController->indexAction() {} vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:153 {▶} vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:68 {▶} vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:202 {▶} web/app_dev.php:33 {▶} } }

I first filed it here: https://github.com/symfony/symfony/issues/25328 But there we realized that the problem has to be with JMSI18nRoutingBundle as disabling the bundle solved the problem.

This is also related to: https://github.com/schmittjoh/JMSI18nRoutingBundle/issues/215

curry684 commented 6 years ago

https://github.com/schmittjoh/JMSI18nRoutingBundle/blob/2.0/DependencyInjection/Compiler/SetRouterPass.php#L33

The alias is not explicitly marked public, and therefore still private. Same problem exists in master branch still.

acasademont commented 6 years ago

Hi all, could you please test the master and/or 2.0 branches and tell me if that commit removes the notice? I don't have a working 3.4 SF installation at the moment. Thanks!

acasademont commented 6 years ago

I'll tag them as soon as you confirm me that :)

sroze commented 6 years ago

For you @edurenye 😉

xchopin commented 6 years ago

Is it fixed yet ? Can't use the router service in symfony 4 :(

curry684 commented 6 years ago

Current fix should be fine (have no test case here either) but technically the best way to do this would be to fetch the original definition and copy its isPublic flag - someone could have overridden it, and if you do an inline replace that should be transparent.

curry684 commented 6 years ago

Is it fixed yet ? Can't use the router service in symfony 4 :(

Of course you can, just not via the $this->get('router') method which is actually 'deprecated'. If you use straight DI and just inject the UrlGeneratorInterface it'll work fine.

xchopin commented 6 years ago

I tested with dev-master it works! Ok thanks; I was using the base controller functions from FrameworkExtraBundle (redirect functions were broken)

sroze commented 6 years ago

$this->get('router') method which is actually 'deprecated'.

This is not deprecated. The router service is public in Symfony4, you can use it. That's why the RedirectController is using it.

curry684 commented 6 years ago

I used the apostrophes on purpose. DI is recommended now over the old direct container access.

acasademont commented 6 years ago

thx for that, i just tagged new releases for both branches :)

acasademont commented 6 years ago

and tagged another one, the fix was not compatible with symfony 2.x, this one sould be the good one. enjoy!