From 820bb3e6019500a4fc35b9f74c19469f9e4bdcc3 Mon Sep 17 00:00:00 2001 From: Maks Rafalko Date: Fri, 22 Nov 2013 20:14:20 +0300 Subject: [PATCH] Changed parameter container to requestStack (2.4+) There is no need to pass @service_container to the voter, @request is enough. please see #3216 --- cookbook/security/voters.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cookbook/security/voters.rst b/cookbook/security/voters.rst index 38e43cd5e0f..7b674e22105 100644 --- a/cookbook/security/voters.rst +++ b/cookbook/security/voters.rst @@ -61,15 +61,18 @@ and compare the IP address against a set of blacklisted IP addresses: // src/Acme/DemoBundle/Security/Authorization/Voter/ClientIpVoter.php namespace Acme\DemoBundle\Security\Authorization\Voter; - use Symfony\Component\DependencyInjection\ContainerInterface; + use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; class ClientIpVoter implements VoterInterface { - public function __construct(ContainerInterface $container, array $blacklistedIp = array()) + protected $requestStack; + protected $blacklistedIp; + + public function __construct(RequestStack $requestStack, array $blacklistedIp = array()) { - $this->container = $container; + $this->requestStack = $requestStack; $this->blacklistedIp = $blacklistedIp; } @@ -87,7 +90,7 @@ and compare the IP address against a set of blacklisted IP addresses: public function vote(TokenInterface $token, $object, array $attributes) { - $request = $this->container->get('request'); + $request = $requestStack->getCurrentRequest(); if (in_array($request->getClientIp(), $this->blacklistedIp)) { return VoterInterface::ACCESS_DENIED; } @@ -124,7 +127,7 @@ and tag it as a "security.voter": services: security.access.blacklist_voter: class: Acme\DemoBundle\Security\Authorization\Voter\ClientIpVoter - arguments: ["@service_container", [123.123.123.123, 171.171.171.171]] + arguments: ["@request_stack", [123.123.123.123, 171.171.171.171]] public: false tags: - { name: security.voter } @@ -134,7 +137,7 @@ and tag it as a "security.voter": - + 123.123.123.123 171.171.171.171 @@ -151,7 +154,7 @@ and tag it as a "security.voter": $definition = new Definition( 'Acme\DemoBundle\Security\Authorization\Voter\ClientIpVoter', array( - new Reference('service_container'), + new Reference('request_stack'), array('123.123.123.123', '171.171.171.171'), ), );