[Validator] Added ObjectInitializer visitor
This commit is contained in:
parent
7e3a41d9db
commit
b1a947737a
@ -45,8 +45,7 @@ class ExecutionContextManager extends AbstractVisitor implements ExecutionContex
|
|||||||
public function __construct(GroupManagerInterface $groupManager)
|
public function __construct(GroupManagerInterface $groupManager)
|
||||||
{
|
{
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
|
$this->contextStack = new \SplStack();
|
||||||
$this->reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initialize(ValidatorInterface $validator)
|
public function initialize(ValidatorInterface $validator)
|
||||||
@ -95,7 +94,7 @@ class ExecutionContextManager extends AbstractVisitor implements ExecutionContex
|
|||||||
|
|
||||||
public function afterTraversal(array $nodes)
|
public function afterTraversal(array $nodes)
|
||||||
{
|
{
|
||||||
$this->reset();
|
$this->contextStack = new \SplStack();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enterNode(Node $node)
|
public function enterNode(Node $node)
|
||||||
@ -115,9 +114,4 @@ class ExecutionContextManager extends AbstractVisitor implements ExecutionContex
|
|||||||
|
|
||||||
$this->currentContext->popNode();
|
$this->currentContext->popNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function reset()
|
|
||||||
{
|
|
||||||
$this->contextStack = new \SplStack();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Validator\NodeVisitor;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Node\ClassNode;
|
||||||
|
use Symfony\Component\Validator\Node\Node;
|
||||||
|
use Symfony\Component\Validator\ObjectInitializerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since %%NextVersion%%
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*/
|
||||||
|
class ObjectInitializer extends AbstractVisitor
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var ObjectInitializerInterface[]
|
||||||
|
*/
|
||||||
|
private $initializers;
|
||||||
|
|
||||||
|
public function __construct(array $initializers)
|
||||||
|
{
|
||||||
|
foreach ($initializers as $initializer) {
|
||||||
|
if (!$initializer instanceof ObjectInitializerInterface) {
|
||||||
|
throw new \LogicException('Validator initializers must implement ObjectInitializerInterface.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->initializers = $initializers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enterNode(Node $node)
|
||||||
|
{
|
||||||
|
if ($node instanceof ClassNode) {
|
||||||
|
foreach ($this->initializers as $initializer) {
|
||||||
|
$initializer->initialize($node->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user