Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 984bd38

Browse files
committed
mades things more consistent for the end user
1 parent d477f15 commit 984bd38

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/StandardFormLogin/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ security:
3131
- { path: ^/secured-by-one-ip$, ip: 10.10.10.10, roles: IS_AUTHENTICATED_ANONYMOUSLY }
3232
- { path: ^/secured-by-two-ips$, ips: [1.1.1.1, 2.2.2.2], roles: IS_AUTHENTICATED_ANONYMOUSLY }
3333
- { path: ^/highly_protected_resource$, roles: IS_ADMIN }
34-
- { path: ^/protected-via-expression$, allow_if: "(is_anonymous() and object.headers.get('user-agent') =~ '/Firefox/i') or has_role('ROLE_USER')" }
34+
- { path: ^/protected-via-expression$, allow_if: "(is_anonymous() and request.headers.get('user-agent') =~ '/Firefox/i') or has_role('ROLE_USER')" }
3535
- { path: .*, roles: IS_AUTHENTICATED_FULLY }

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ public function resolveServices($value)
10081008
} elseif ($value instanceof Definition) {
10091009
$value = $this->createService($value, null);
10101010
} elseif ($value instanceof Expression) {
1011-
$value = $this->getExpressionLanguage()->evaluate($value, array('this' => $this));
1011+
$value = $this->getExpressionLanguage()->evaluate($value, array('container' => $this));
10121012
}
10131013

10141014
return $value;

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ private function dumpValue($value, $interpolate = true)
12011201

12021202
return $this->getServiceCall((string) $value, $value);
12031203
} elseif ($value instanceof Expression) {
1204-
return $this->getExpressionLanguage()->compile((string) $value, array('this'));
1204+
return $this->getExpressionLanguage()->compile((string) $value, array('container'));
12051205
} elseif ($value instanceof Parameter) {
12061206
return $this->dumpParameter($value);
12071207
} elseif (true === $interpolate && is_string($value)) {

src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Security\Core\Authorization\ExpressionLanguage;
1717
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
1818
use Symfony\Component\ExpressionLanguage\Expression;
19+
use Symfony\Component\HttpFoundation\Request;
1920

2021
/**
2122
* ExpressionVoter votes based on the evaluation of an expression.
@@ -75,6 +76,13 @@ public function vote(TokenInterface $token, $object, array $attributes)
7576
'trust_resolver' => $this->trustResolver,
7677
);
7778

79+
// this is mainly to propose a better experience when the expression is used
80+
// in an access control rule, as the developer does not know that it's going
81+
// to be handled by this voter
82+
if ($object instanceof Request) {
83+
$variables['request'] = $object;
84+
}
85+
7886
$result = VoterInterface::ACCESS_ABSTAIN;
7987
foreach ($attributes as $attribute) {
8088
if (!$this->supportsAttribute($attribute)) {

0 commit comments

Comments
 (0)