Symfony 2.4.2: you cannot create a service ("request") inactive area ("request")

I just upgraded the project to Symfony 2.4.2, starting with 2.2.2. After updating, the profiler raises an exception, which is displayed in the line at the bottom of each page:

'Symfony \ Component \ DependencyInjection \ Exception \ InactiveScopeException' with the message 'You cannot create a service ("request") of the inactive area ("request").

( ! ) Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\InactiveScopeException' with message 'You cannot create a service ("request") of an inactive scope ("request").' in /var/www/pm/app/cache/dev/appDevDebugProjectContainer.php on line 3776 ( ! ) Symfony\Component\DependencyInjection\Exception\InactiveScopeException: You cannot create a service ("request") of an inactive scope ("request"). in /var/www/pm/app/cache/dev/appDevDebugProjectContainer.php on line 3776 Call Stack # Time Memory Function Location 1 0.0029 239928 {main}( ) ../app_dev.php:0 2 4.0354 53462264 Symfony\Component\HttpKernel\Kernel->terminate( ) ../app_dev.php:18 3 4.0355 53462360 Symfony\Component\HttpKernel\HttpKernel->terminate( ) ../bootstrap.php.cache:2283 4 4.0371 53473320 Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->dispatch( ) ../bootstrap.php.cache:2894 5 4.0377 53477632 Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch( ) ../TraceableEventDispatcher.php:138 6 4.0377 53477632 Symfony\Component\EventDispatcher\EventDispatcher->dispatch( ) ../classes.php:1831 7 4.0377 53477696 Symfony\Component\EventDispatcher\EventDispatcher->doDispatch( ) ../classes.php:1667 8 4.0377 53478048 call_user_func ( ) ../classes.php:1734 9 4.0377 53478088 Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->Symfony\Component\HttpKernel\Debug\{closure}( ) ../classes.php:1734 10 4.0385 53482400 call_user_func ( ) ../TraceableEventDispatcher.php:388 11 4.0385 53482440 Symfony\Component\HttpKernel\EventListener\ProfilerListener->onKernelTerminate( ) ../TraceableEventDispatcher.php:388 12 4.0387 53486304 Symfony\Component\HttpKernel\Profiler\Profiler->saveProfile( ) ../ProfilerListener.php:136 13 4.0388 53486480 Symfony\Component\HttpKernel\DataCollector\EventDataCollector->lateCollect( ) ../Profiler.php:115 14 4.0388 53486544 Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->getNotCalledListeners( ) ../EventDataCollector.php:48 15 4.0388 53486752 Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher->getListeners( ) ../TraceableEventDispatcher.php:166 16 4.0388 53486848 Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->getListeners( ) ../TraceableEventDispatcher.php:106 17 4.0403 53497920 Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->lazyLoad( ) ../classes.php:1807 18 4.0416 53520352 Symfony\Component\DependencyInjection\Container->get( ) ../classes.php:1842 

It seems that an error occurs when the profiler listens for kernel termination, but I could not solve the problem.

What's wrong?

Edit

An example of a service that has a request:

 services: property.value.form.resolver.number: class: Frisbee\ProductBundle\Form\Resolver\PropertyTypeFormResolverNumber arguments: [@form.factory, @request] scope: request 
+2
php symfony
source share
1 answer

Please try one of the following approaches to eliminate this exception:

  • Remove scope: request and change arguments: [@form.factory, @request] to arguments: [@form.factory, @request=]

  • use the synchronized service available with Symfony 2.3, where synchronized: true needs to be added to the service configuration and setter function for the class. The request is specified using Symfony DI, if available in the scope. Link ( http://symfony.com/doc/current/cookbook/service_container/scopes.html ):

 services: property.value.form.resolver.number: class: Frisbee\ProductBundle\Form\Resolver\PropertyTypeFormResolverNumber arguments: [@form.factory] synchronized: true calls: - [setRequest, ["@?request="]] 
  /** * @param Request $request */ public function setRequest(Request $request = null) { if ($request !== null) { $this->request = $request; } } 
  • adding lazy: true to the configuration can also help:
 services: property.value.form.resolver.number: class: Frisbee\ProductBundle\Form\Resolver\PropertyTypeFormResolverNumber arguments: [@form.factory, @request] scope: request lazy: true 
+1
source share

All Articles