Skip to content

Commit

Permalink
RE #193: Added default values
Browse files Browse the repository at this point in the history
Ignore $authorizationChecker is not initilized
  • Loading branch information
excelwebzone committed Feb 23, 2018
1 parent 3e6ff3b commit ae542b3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getConfigTreeBuilder()
->booleanNode('ajax')->defaultFalse()->end()
->scalarNode('locale_key')->defaultValue('%kernel.default_locale%')->end()
->booleanNode('locale_from_request')->defaultFalse()->end()
->arrayNode('trusted_roles')->prototype('scalar')->end()
->arrayNode('trusted_roles')->prototype('scalar')->treatNullLike(array())->end()
->end()
;

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
- '@request_stack'
- '%ewz_recaptcha.http_proxy%'
- '%ewz_recaptcha.verify_host%'
- '@security.authorization_checker'
- '@?security.authorization_checker'
- '%ewz_recaptcha.trusted_roles%'
tags:
- { name: validator.constraint_validator, alias: 'ewz_recaptcha.true' }
23 changes: 16 additions & 7 deletions src/Validator/Constraints/IsTrueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,22 @@ class IsTrueValidator extends ConstraintValidator
const RECAPTCHA_VERIFY_SERVER = 'https://www.google.com';

/**
* @param bool $enabled
* @param string $privateKey
* @param RequestStack $requestStack
* @param array $httpProxy
* @param bool $verifyHost
* @param bool $enabled
* @param string $privateKey
* @param RequestStack $requestStack
* @param array $httpProxy
* @param bool $verifyHost
* @param AuthorizationCheckerInterface|null $authorizationChecker
* @param array $trusted_roles
*/
public function __construct($enabled, $privateKey, RequestStack $requestStack, array $httpProxy, $verifyHost, AuthorizationCheckerInterface $authorizationChecker, $trusted_roles)
public function __construct(
$enabled,
$privateKey,
RequestStack $requestStack,
array $httpProxy,
$verifyHost,
AuthorizationCheckerInterface $authorizationChecker = null,
array $trusted_roles = array())
{
$this->enabled = $enabled;
$this->privateKey = $privateKey;
Expand All @@ -93,7 +102,7 @@ public function validate($value, Constraint $constraint)
}

// if we have an authorized role
if ($this->authorizationChecker->isGranted($this->trusted_roles)) {
if ($this->authorizationChecker && $this->authorizationChecker->isGranted($this->trusted_roles)) {
return true;
}

Expand Down

0 comments on commit ae542b3

Please sign in to comment.