Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2.8: isScopeActive deprecation after update to 2.8.0 from 2.7.7

I've updated to symfony 2.8 from 2.7.7 and i get this deprecation:

The Symfony\Component\DependencyInjection\Container::isScopeActive method is deprecated since version 2.8 and will be removed in 3.0.

I use this call in a twig extension class:

class TemplateHelper extends \Twig_Extension {

    private $request;

    private $container;


    /**
     * constructor
     * @param ContainerInterface $container
     */
    public function __construct(ContainerInterface $container){
        $this->container = $container;

        if( $this->container->isScopeActive('request') ){
            $this->request = $this->container->get('request');
        }
    }
    //...functions
    }

Firstly i delete the isScopeActive check, but i get an exception when i run the symfony cache clear:

[Symfony\Component\DependencyInjection\Exception\InactiveScopeException] You cannot create a service ("request") of an inactive scope ("request").

Is there any way to replace the isScopeActive check?

Thanks...

like image 914
ar099968 Avatar asked Dec 07 '15 15:12

ar099968


1 Answers

Simply inject request_stack instead of request and call getCurrentRequest().

like image 100
Mantas Avatar answered Sep 28 '22 06:09

Mantas