Skip to content

Commit e057b19

Browse files
committed
[Validator] Decoupled ContextRefresher from ExecutionContext
1 parent e440690 commit e057b19

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/Symfony/Component/Validator/Context/ExecutionContext.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Validator\Group\GroupManagerInterface;
2121
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
2222
use Symfony\Component\Validator\Node\Node;
23+
use Symfony\Component\Validator\Util\NodeStackInterface;
2324
use Symfony\Component\Validator\Util\PropertyPath;
2425
use Symfony\Component\Validator\Validator\ValidatorInterface;
2526
use Symfony\Component\Validator\Violation\ConstraintViolationBuilder;
@@ -32,7 +33,7 @@
3233
*
3334
* @see ExecutionContextInterface
3435
*/
35-
class ExecutionContext implements ExecutionContextInterface, LegacyExecutionContextInterface
36+
class ExecutionContext implements ExecutionContextInterface, LegacyExecutionContextInterface, NodeStackInterface
3637
{
3738
/**
3839
* @var ValidatorInterface

src/Symfony/Component/Validator/NodeVisitor/ContextRefresher.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
namespace Symfony\Component\Validator\NodeVisitor;
1313

14-
use Symfony\Component\Validator\Context\ExecutionContext;
1514
use Symfony\Component\Validator\Context\ExecutionContextInterface;
1615
use Symfony\Component\Validator\Exception\RuntimeException;
1716
use Symfony\Component\Validator\Node\Node;
17+
use Symfony\Component\Validator\Util\NodeStackInterface;
1818

1919
/**
2020
* Updates the current context with the current node of the validation
@@ -27,7 +27,7 @@ class ContextRefresher extends AbstractVisitor
2727
{
2828
public function enterNode(Node $node, ExecutionContextInterface $context)
2929
{
30-
if (!$context instanceof ExecutionContext) {
30+
if (!$context instanceof NodeStackInterface) {
3131
throw new RuntimeException(sprintf(
3232
'The ContextRefresher only supports instances of class '.
3333
'"Symfony\Component\Validator\Context\ExecutionContext". '.
@@ -46,7 +46,7 @@ public function enterNode(Node $node, ExecutionContextInterface $context)
4646
*/
4747
public function leaveNode(Node $node, ExecutionContextInterface $context)
4848
{
49-
if (!$context instanceof ExecutionContext) {
49+
if (!$context instanceof NodeStackInterface) {
5050
throw new RuntimeException(sprintf(
5151
'The ContextRefresher only supports instances of class '.
5252
'"Symfony\Component\Validator\Context\ExecutionContext". '.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Validator\Util;
13+
14+
use Symfony\Component\Validator\Node\Node;
15+
16+
/**
17+
* @since %%NextVersion%%
18+
* @author Bernhard Schussek <[email protected]>
19+
*/
20+
interface NodeStackInterface
21+
{
22+
public function pushNode(Node $node);
23+
24+
public function popNode();
25+
}

0 commit comments

Comments
 (0)