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

Appearance settings

Commit cf7d0d9

Browse filesBrowse files
committed
Code review
1 parent 30c3f13 commit cf7d0d9
Copy full SHA for cf7d0d9

File tree

5 files changed

+33
-14
lines changed
Filter options

5 files changed

+33
-14
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/EventListener/ExpressionLanguage.php
+7-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/EventListener/GuardListener.php
+3-10Lines 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)
+21Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Tests/EventListener/GuardListenerTest.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ protected function setUp()
3131
$this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock();
3232
$authenticationChecker = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock();
3333
$trustResolver = $this->getMockBuilder(AuthenticationTrustResolverInterface::class)->getMock();
34-
$validator = $this->getMockBuilder(ValidatorInterface::class)->getMock();
3534

36-
$this->listener = new GuardListener($configuration, $expressionLanguage, $this->tokenStorage, $authenticationChecker, $trustResolver, $validator);
35+
$this->listener = new GuardListener($configuration, $expressionLanguage, $this->tokenStorage, $authenticationChecker, $trustResolver);
3736
}
3837

3938
protected function tearDown()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.