Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4dba1ac

Browse files
maks-rafalkoweaverryan
authored andcommitted
Changed parameter container to requestStack (2.4+)
There is no need to pass @service_container to the voter,@request is enough.please seesymfony#3216
1 parent08de8b2 commit4dba1ac

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

‎cookbook/security/voters.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,18 @@ and compare the IP address against a set of blacklisted IP addresses:
6161
// src/Acme/DemoBundle/Security/Authorization/Voter/ClientIpVoter.php
6262
namespace Acme\DemoBundle\Security\Authorization\Voter;
6363
64-
use Symfony\Component\DependencyInjection\ContainerInterface;
64+
use Symfony\Component\HttpFoundation\RequestStack;
6565
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
6666
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
6767
6868
class ClientIpVoter implements VoterInterface
6969
{
70-
private $container;
71-
70+
protected $requestStack;
7271
private $blacklistedIp;
73-
74-
public function __construct(ContainerInterface $container, array $blacklistedIp = array())
72+
73+
public function __construct(RequestStack $requestStack, array $blacklistedIp = array())
7574
{
76-
$this->container= $container;
75+
$this->requestStack= $requestStack;
7776
$this->blacklistedIp = $blacklistedIp;
7877
}
7978
@@ -91,7 +90,7 @@ and compare the IP address against a set of blacklisted IP addresses:
9190
9291
public function vote(TokenInterface $token, $object, array $attributes)
9392
{
94-
$request = $this->container->get('request');
93+
$request = $this->requestStack->getCurrentRequest();
9594
if (in_array($request->getClientIp(), $this->blacklistedIp)) {
9695
return VoterInterface::ACCESS_DENIED;
9796
}
@@ -128,7 +127,7 @@ and tag it as a ``security.voter``:
128127
services:
129128
security.access.blacklist_voter:
130129
class:Acme\DemoBundle\Security\Authorization\Voter\ClientIpVoter
131-
arguments:["@service_container", [123.123.123.123, 171.171.171.171]]
130+
arguments:["@request_stack", [123.123.123.123, 171.171.171.171]]
132131
public:false
133132
tags:
134133
-{ name: security.voter }
@@ -138,7 +137,7 @@ and tag it as a ``security.voter``:
138137
<!-- src/Acme/AcmeBundle/Resources/config/services.xml-->
139138
<serviceid="security.access.blacklist_voter"
140139
class="Acme\DemoBundle\Security\Authorization\Voter\ClientIpVoter"public="false">
141-
<argumenttype="service"id="service_container"strict="false" />
140+
<argumenttype="service"id="request_stack"strict="false" />
142141
<argumenttype="collection">
143142
<argument>123.123.123.123</argument>
144143
<argument>171.171.171.171</argument>
@@ -155,7 +154,7 @@ and tag it as a ``security.voter``:
155154
$definition = new Definition(
156155
'Acme\DemoBundle\Security\Authorization\Voter\ClientIpVoter',
157156
array(
158-
new Reference('service_container'),
157+
new Reference('request_stack'),
159158
array('123.123.123.123', '171.171.171.171'),
160159
),
161160
);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp