Skip to content

Commit ae542b3

Browse files
committed
RE #193: Added default values
Ignore $authorizationChecker is not initilized
1 parent 3e6ff3b commit ae542b3

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function getConfigTreeBuilder()
2828
->booleanNode('ajax')->defaultFalse()->end()
2929
->scalarNode('locale_key')->defaultValue('%kernel.default_locale%')->end()
3030
->booleanNode('locale_from_request')->defaultFalse()->end()
31-
->arrayNode('trusted_roles')->prototype('scalar')->end()
31+
->arrayNode('trusted_roles')->prototype('scalar')->treatNullLike(array())->end()
3232
->end()
3333
;
3434

src/Resources/config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ services:
2727
- '@request_stack'
2828
- '%ewz_recaptcha.http_proxy%'
2929
- '%ewz_recaptcha.verify_host%'
30-
- '@security.authorization_checker'
30+
- '@?security.authorization_checker'
3131
- '%ewz_recaptcha.trusted_roles%'
3232
tags:
3333
- { name: validator.constraint_validator, alias: 'ewz_recaptcha.true' }

src/Validator/Constraints/IsTrueValidator.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,22 @@ class IsTrueValidator extends ConstraintValidator
6565
const RECAPTCHA_VERIFY_SERVER = 'https://www.google.com';
6666

6767
/**
68-
* @param bool $enabled
69-
* @param string $privateKey
70-
* @param RequestStack $requestStack
71-
* @param array $httpProxy
72-
* @param bool $verifyHost
68+
* @param bool $enabled
69+
* @param string $privateKey
70+
* @param RequestStack $requestStack
71+
* @param array $httpProxy
72+
* @param bool $verifyHost
73+
* @param AuthorizationCheckerInterface|null $authorizationChecker
74+
* @param array $trusted_roles
7375
*/
74-
public function __construct($enabled, $privateKey, RequestStack $requestStack, array $httpProxy, $verifyHost, AuthorizationCheckerInterface $authorizationChecker, $trusted_roles)
76+
public function __construct(
77+
$enabled,
78+
$privateKey,
79+
RequestStack $requestStack,
80+
array $httpProxy,
81+
$verifyHost,
82+
AuthorizationCheckerInterface $authorizationChecker = null,
83+
array $trusted_roles = array())
7584
{
7685
$this->enabled = $enabled;
7786
$this->privateKey = $privateKey;
@@ -93,7 +102,7 @@ public function validate($value, Constraint $constraint)
93102
}
94103

95104
// if we have an authorized role
96-
if ($this->authorizationChecker->isGranted($this->trusted_roles)) {
105+
if ($this->authorizationChecker && $this->authorizationChecker->isGranted($this->trusted_roles)) {
97106
return true;
98107
}
99108

0 commit comments

Comments
 (0)