8000 Code review · symfony/symfony@cf7d0d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf7d0d9

Browse files
committed
Code review
1 parent 30c3f13 commit cf7d0d9

File tree

5 files changed

+33
-14
lines changed
  • Tests/EventListener
  • 5 files changed

    +33
    -14
    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 & 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