removed deprecated notices when using the security service

This commit is contained in:
Fabien Potencier 2015-01-19 23:54:06 +01:00
parent 1067cc5815
commit 09ed9b5495
2 changed files with 7 additions and 7 deletions

View File

@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Exposes some Symfony parameters and services as an "app" global variable. * Exposes some Symfony parameters and services as an "app" global variable.
@ -25,7 +25,7 @@ use Symfony\Component\Security\Core\SecurityContextInterface;
*/ */
class AppVariable class AppVariable
{ {
private $security; private $container;
private $tokenStorage; private $tokenStorage;
private $requestStack; private $requestStack;
private $environment; private $environment;
@ -34,9 +34,9 @@ class AppVariable
/** /**
* @deprecated since version 2.7, to be removed in 3.0. * @deprecated since version 2.7, to be removed in 3.0.
*/ */
public function setSecurity(SecurityContextInterface $security) public function setContainer(ContainerInterface $container)
{ {
$this->security = $security; $this->container = $container;
} }
public function setTokenStorage(TokenStorageInterface $tokenStorage) public function setTokenStorage(TokenStorageInterface $tokenStorage)
@ -70,11 +70,11 @@ class AppVariable
{ {
trigger_error('The "app.security" variable is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED); trigger_error('The "app.security" variable is deprecated since version 2.6 and will be removed in 3.0.', E_USER_DEPRECATED);
if (null === $this->security) { if (null === $this->container) {
throw new \RuntimeException('The "app.security" variable is not available.'); throw new \RuntimeException('The "app.security" variable is not available.');
} }
return $this->security; return $this->container->get('security');
} }
/** /**

View File

@ -41,7 +41,7 @@
<service id="twig.app_variable" class="Symfony\Bridge\Twig\AppVariable" public="false"> <service id="twig.app_variable" class="Symfony\Bridge\Twig\AppVariable" public="false">
<call method="setEnvironment"><argument>%kernel.environment%</argument></call> <call method="setEnvironment"><argument>%kernel.environment%</argument></call>
<call method="setDebug"><argument>%kernel.debug%</argument></call> <call method="setDebug"><argument>%kernel.debug%</argument></call>
<call method="setSecurity"><argument type="service" id="security.context" on-invalid="ignore" /></call> <call method="setContainer"><argument type="service" id="service_container" /></call>
<call method="setTokenStorage"><argument type="service" id="security.token_storage" on-invalid="ignore" /></call> <call method="setTokenStorage"><argument type="service" id="security.token_storage" on-invalid="ignore" /></call>
<call method="setRequestStack"><argument type="service" id="request_stack" on-invalid="ignore" /></call> <call method="setRequestStack"><argument type="service" id="request_stack" on-invalid="ignore" /></call>
</service> </service>