Skip to content

Commit adb227f

Browse files
committed
Code review
1 parent 2d014c8 commit adb227f

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
632632
new Reference('security.token_storage'),
633633
new Reference('security.authorization_checker'),
634634
new Reference('security.authentication.trust_resolver'),
635-
new Reference('validator'),
636635
new Reference('security.role_hierarchy'),
636+
new Reference('validator'),
637637
));
638638

639639
$container->setDefinition(sprintf('%s.listener.guard', $workflowId), $guard);

src/Symfony/Component/Workflow/EventListener/ExpressionLanguage.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\Workflow\EventListener;
1313

1414
use Symfony\Component\Security\Core\Authorization\ExpressionLanguage as BaseExpressionLanguage;
15+
use Symfony\Component\Validator\Validator\ValidatorInterface;
16+
use Symfony\Component\Workflow\Exception\RuntimeException;
1517

1618
/**
1719
* Adds some function to the default Symfony Security ExpressionLanguage.
@@ -31,8 +33,12 @@ protected function registerFunctions()
3133
});
3234

3335
$this->register('is_valid', function ($object = 'null', $groups = 'null') {
34-
return sprintf('$validator->validate(%s, null, %s)', $object, $groups);
36+
return sprintf('count($validator->validate(%s, null, %s)) === 0', $object, $groups);
3537
}, function (array $variables, $object = null, $groups = null) {
38+
if (!$variables['validator'] instanceof ValidatorInterface) {
39+
throw new RuntimeException('Validator not defined, did you install the component ?');
40+
}
41+
3642
$errors = $variables['validator']->validate($object, null, $groups);
3743

3844
return count($errors) === 0;

src/Symfony/Component/Workflow/EventListener/GuardListener.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,15 @@ class GuardListener
3131
private $roleHierarchy;
3232
private $validator;
3333

34-
public function __construct(
35-
$configuration,
36-
ExpressionLanguage $expressionLanguage,
37-
TokenStorageInterface $tokenStorage,
38-
AuthorizationCheckerInterface $authenticationChecker,
39-
AuthenticationTrustResolverInterface $trustResolver,
40-
ValidatorInterface $validator,
41-
RoleHierarchyInterface $roleHierarchy = null
42-
) {
34+
public function __construct($configuration, ExpressionLanguage $expressionLanguage, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authenticationChecker, AuthenticationTrustResolverInterface $trustResolver, RoleHierarchyInterface $roleHierarchy = null, ValidatorInterface $validator = null)
35+
{
4336
$this->configuration = $configuration;
4437
$this->expressionLanguage = $expressionLanguage;
4538
$this->tokenStorage = $tokenStorage;
4639
$this->authenticationChecker = $authenticationChecker;
4740
$this->trustResolver = $trustResolver;
48-
$this->validator = $validator;
4941
$this->roleHierarchy = $roleHierarchy;
42+
$this->validator = $validator;
5043
}
5144

5245
public function onTransition(GuardEvent $event, $eventName)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Workflow\Exception;
13+
14+
/**
15+
* Base RuntimeException for the Workflow component.
16+
*
17+
* @author Alain Flaus <alain.flaus@gmail.com>
18+
*/
19+
class RuntimeException extends \RuntimeException implements ExceptionInterface
20+
{
21+
}

src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
99
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1010
use Symfony\Component\Security\Core\Role\Role;
11-
use Symfony\Component\Validator\Validator\ValidatorInterface;
1211
use Symfony\Component\Workflow\EventListener\ExpressionLanguage;
1312
use Symfony\Component\Workflow\EventListener\GuardListener;
1413
use Symfony\Component\Workflow\Event\GuardEvent;
@@ -31,9 +30,8 @@ protected function setUp()
3130
$this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock();
3231
$authenticationChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
3332
$trustResolver = $this->getMockBuilder(AuthenticationTrustResolverInterface::class)->getMock();
34-
$validator = $this->getMockBuilder(ValidatorInterface::class)->getMock();
3533

36-
$this->listener = new GuardListener($configuration, $expressionLanguage, $this->tokenStorage, $authenticationChecker, $trustResolver, $validator);
34+
$this->listener = new GuardListener($configuration, $expressionLanguage, $this->tokenStorage, $authenticationChecker, $trustResolver);
3735
}
3836

3937
protected function tearDown()

0 commit comments

Comments
 (0)