[Validator] Removed helper class Traversal
This commit is contained in:
parent
76d8c9a1f7
commit
778ec2458b
@ -74,20 +74,20 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$traversal = new Traversal($context);
|
$nodeQueue = new \SplQueue();
|
||||||
|
|
||||||
foreach ($nodes as $node) {
|
foreach ($nodes as $node) {
|
||||||
$traversal->nodeQueue->enqueue($node);
|
$nodeQueue->enqueue($node);
|
||||||
|
|
||||||
while (!$traversal->nodeQueue->isEmpty()) {
|
while (!$nodeQueue->isEmpty()) {
|
||||||
$node = $traversal->nodeQueue->dequeue();
|
$node = $nodeQueue->dequeue();
|
||||||
|
|
||||||
if ($node instanceof ClassNode) {
|
if ($node instanceof ClassNode) {
|
||||||
$this->traverseClassNode($node, $traversal);
|
$this->traverseClassNode($node, $nodeQueue, $context);
|
||||||
} elseif ($node instanceof CollectionNode) {
|
} elseif ($node instanceof CollectionNode) {
|
||||||
$this->traverseCollectionNode($node, $traversal);
|
$this->traverseCollectionNode($node, $nodeQueue, $context);
|
||||||
} else {
|
} else {
|
||||||
$this->traverseNode($node, $traversal);
|
$this->traverseNode($node, $nodeQueue, $context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function traverseNode(Node $node, Traversal $traversal)
|
private function traverseNode(Node $node, \SplQueue $nodeQueue, ExecutionContextInterface $context)
|
||||||
{
|
{
|
||||||
// Visitors have two possibilities to influence the traversal:
|
// Visitors have two possibilities to influence the traversal:
|
||||||
//
|
//
|
||||||
@ -122,7 +122,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
// 2. If a visitor's visit() method removes a group from the node,
|
// 2. If a visitor's visit() method removes a group from the node,
|
||||||
// that group will be skipped in the subtree of that node.
|
// that group will be skipped in the subtree of that node.
|
||||||
|
|
||||||
if (false === $this->visit($node, $traversal->context)) {
|
if (false === $this->visit($node, $context)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
// Arrays are always traversed, independent of the specified
|
// Arrays are always traversed, independent of the specified
|
||||||
// traversal strategy
|
// traversal strategy
|
||||||
// (BC with Symfony < 2.5)
|
// (BC with Symfony < 2.5)
|
||||||
$traversal->nodeQueue->enqueue(new CollectionNode(
|
$nodeQueue->enqueue(new CollectionNode(
|
||||||
$node->value,
|
$node->value,
|
||||||
$node->propertyPath,
|
$node->propertyPath,
|
||||||
$cascadedGroups,
|
$cascadedGroups,
|
||||||
@ -167,7 +167,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
$node->propertyPath,
|
$node->propertyPath,
|
||||||
$cascadedGroups,
|
$cascadedGroups,
|
||||||
$traversalStrategy,
|
$traversalStrategy,
|
||||||
$traversal
|
$nodeQueue
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -184,7 +184,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If TRAVERSE, the constructor will fail if we have no Traversable
|
// If TRAVERSE, the constructor will fail if we have no Traversable
|
||||||
$traversal->nodeQueue->enqueue(new CollectionNode(
|
$nodeQueue->enqueue(new CollectionNode(
|
||||||
$node->value,
|
$node->value,
|
||||||
$node->propertyPath,
|
$node->propertyPath,
|
||||||
$cascadedGroups,
|
$cascadedGroups,
|
||||||
@ -193,7 +193,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function traverseClassNode(ClassNode $node, Traversal $traversal)
|
private function traverseClassNode(ClassNode $node, \SplQueue $nodeQueue, ExecutionContextInterface $context)
|
||||||
{
|
{
|
||||||
// Visitors have two possibilities to influence the traversal:
|
// Visitors have two possibilities to influence the traversal:
|
||||||
//
|
//
|
||||||
@ -202,7 +202,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
// 2. If a visitor's visit() method removes a group from the node,
|
// 2. If a visitor's visit() method removes a group from the node,
|
||||||
// that group will be skipped in the subtree of that node.
|
// that group will be skipped in the subtree of that node.
|
||||||
|
|
||||||
if (false === $this->visit($node, $traversal->context)) {
|
if (false === $this->visit($node, $context)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
|
|
||||||
foreach ($node->metadata->getConstrainedProperties() as $propertyName) {
|
foreach ($node->metadata->getConstrainedProperties() as $propertyName) {
|
||||||
foreach ($node->metadata->getPropertyMetadata($propertyName) as $propertyMetadata) {
|
foreach ($node->metadata->getPropertyMetadata($propertyName) as $propertyMetadata) {
|
||||||
$traversal->nodeQueue->enqueue(new PropertyNode(
|
$nodeQueue->enqueue(new PropertyNode(
|
||||||
$node->value,
|
$node->value,
|
||||||
$propertyMetadata->getPropertyValue($node->value),
|
$propertyMetadata->getPropertyValue($node->value),
|
||||||
$propertyMetadata,
|
$propertyMetadata,
|
||||||
@ -246,7 +246,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If TRAVERSE, the constructor will fail if we have no Traversable
|
// If TRAVERSE, the constructor will fail if we have no Traversable
|
||||||
$traversal->nodeQueue->enqueue(new CollectionNode(
|
$nodeQueue->enqueue(new CollectionNode(
|
||||||
$node->value,
|
$node->value,
|
||||||
$node->propertyPath,
|
$node->propertyPath,
|
||||||
$node->groups,
|
$node->groups,
|
||||||
@ -255,7 +255,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function traverseCollectionNode(CollectionNode $node, Traversal $traversal)
|
private function traverseCollectionNode(CollectionNode $node, \SplQueue $nodeQueue, ExecutionContextInterface $context)
|
||||||
{
|
{
|
||||||
// Visitors have two possibilities to influence the traversal:
|
// Visitors have two possibilities to influence the traversal:
|
||||||
//
|
//
|
||||||
@ -264,7 +264,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
// 2. If a visitor's visit() method removes a group from the node,
|
// 2. If a visitor's visit() method removes a group from the node,
|
||||||
// that group will be skipped in the subtree of that node.
|
// that group will be skipped in the subtree of that node.
|
||||||
|
|
||||||
if (false === $this->visit($node, $traversal->context)) {
|
if (false === $this->visit($node, $context)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,7 +285,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
// Arrays are always cascaded, independent of the specified
|
// Arrays are always cascaded, independent of the specified
|
||||||
// traversal strategy
|
// traversal strategy
|
||||||
// (BC with Symfony < 2.5)
|
// (BC with Symfony < 2.5)
|
||||||
$traversal->nodeQueue->enqueue(new CollectionNode(
|
$nodeQueue->enqueue(new CollectionNode(
|
||||||
$value,
|
$value,
|
||||||
$node->propertyPath.'['.$key.']',
|
$node->propertyPath.'['.$key.']',
|
||||||
$node->groups,
|
$node->groups,
|
||||||
@ -304,13 +304,13 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
$node->propertyPath.'['.$key.']',
|
$node->propertyPath.'['.$key.']',
|
||||||
$node->groups,
|
$node->groups,
|
||||||
$traversalStrategy,
|
$traversalStrategy,
|
||||||
$traversal
|
$nodeQueue
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function cascadeObject($object, $propertyPath, array $groups, $traversalStrategy, Traversal $traversal)
|
private function cascadeObject($object, $propertyPath, array $groups, $traversalStrategy, \SplQueue $nodeQueue)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$classMetadata = $this->metadataFactory->getMetadataFor($object);
|
$classMetadata = $this->metadataFactory->getMetadataFor($object);
|
||||||
@ -319,7 +319,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
// error
|
// error
|
||||||
}
|
}
|
||||||
|
|
||||||
$traversal->nodeQueue->enqueue(new ClassNode(
|
$nodeQueue->enqueue(new ClassNode(
|
||||||
$object,
|
$object,
|
||||||
$classMetadata,
|
$classMetadata,
|
||||||
$propertyPath,
|
$propertyPath,
|
||||||
@ -338,7 +338,7 @@ class NodeTraverser implements NodeTraverserInterface
|
|||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
$traversal->nodeQueue->enqueue(new CollectionNode(
|
$nodeQueue->enqueue(new CollectionNode(
|
||||||
$object,
|
$object,
|
||||||
$propertyPath,
|
$propertyPath,
|
||||||
$groups,
|
$groups,
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
<?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\NodeTraverser;
|
|
||||||
|
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @since %%NextVersion%%
|
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
|
||||||
*/
|
|
||||||
class Traversal
|
|
||||||
{
|
|
||||||
public $context;
|
|
||||||
|
|
||||||
public $nodeQueue;
|
|
||||||
|
|
||||||
public function __construct(ExecutionContextInterface $context)
|
|
||||||
{
|
|
||||||
$this->context = $context;
|
|
||||||
$this->nodeQueue = new \SplQueue();
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user