[Validator] Reduced number of method calls on the execution context

This commit is contained in:
Bernhard Schussek 2014-03-17 17:55:15 +01:00
parent 73c9cc5806
commit 2f23d9725b
4 changed files with 29 additions and 74 deletions

View File

@ -139,24 +139,10 @@ class ExecutionContext implements ExecutionContextInterface
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setValue($value) public function setNode($value, MetadataInterface $metadata = null, $propertyPath)
{ {
$this->value = $value; $this->value = $value;
}
/**
* {@inheritdoc}
*/
public function setMetadata(MetadataInterface $metadata = null)
{
$this->metadata = $metadata; $this->metadata = $metadata;
}
/**
* {@inheritdoc}
*/
public function setPropertyPath($propertyPath)
{
$this->propertyPath = (string) $propertyPath; $this->propertyPath = (string) $propertyPath;
} }

View File

@ -103,31 +103,13 @@ interface ExecutionContextInterface extends LegacyExecutionContextInterface
* Sets the currently validated value. * Sets the currently validated value.
* *
* @param mixed $value The validated value * @param mixed $value The validated value
*
* @internal Used by the validator engine. Should not be called by user
* code.
*/
public function setValue($value);
/**
* Sets the current validation metadata.
*
* @param MetadataInterface $metadata The validation metadata * @param MetadataInterface $metadata The validation metadata
*
* @internal Used by the validator engine. Should not be called by user
* code.
*/
public function setMetadata(MetadataInterface $metadata = null);
/**
* Sets the property path leading to the current value.
*
* @param string $propertyPath The property path to the current value * @param string $propertyPath The property path to the current value
* *
* @internal Used by the validator engine. Should not be called by user * @internal Used by the validator engine. Should not be called by user
* code. * code.
*/ */
public function setPropertyPath($propertyPath); public function setNode($value, MetadataInterface $metadata = null, $propertyPath);
/** /**
* Sets the currently validated group. * Sets the currently validated group.

View File

@ -69,9 +69,7 @@ class NodeValidationVisitor extends AbstractVisitor
return true; return true;
} }
$context->setValue($node->value); $context->setNode($node->value, $node->metadata, $node->propertyPath);
$context->setMetadata($node->metadata);
$context->setPropertyPath($node->propertyPath);
if ($node instanceof ClassNode) { if ($node instanceof ClassNode) {
$this->replaceDefaultGroup($node); $this->replaceDefaultGroup($node);
@ -171,7 +169,6 @@ class NodeValidationVisitor extends AbstractVisitor
*/ */
private function validateNodeForGroup(Node $node, $group, ExecutionContextInterface $context, $objectHash) private function validateNodeForGroup(Node $node, $group, ExecutionContextInterface $context, $objectHash)
{ {
try {
$context->setGroup($group); $context->setGroup($group);
foreach ($node->metadata->findConstraints($group) as $constraint) { foreach ($node->metadata->findConstraints($group) as $constraint) {
@ -201,14 +198,6 @@ class NodeValidationVisitor extends AbstractVisitor
$validator->initialize($context); $validator->initialize($context);
$validator->validate($node->value, $constraint); $validator->validate($node->value, $constraint);
} }
$context->setGroup(null);
} catch (\Exception $e) {
// Should be put into a finally block once we switch to PHP 5.5
$context->setGroup(null);
throw $e;
}
} }
/** /**

View File

@ -581,9 +581,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
*/ */
public function validateNode($value, $valueHash, $container, $containerHash, MetadataInterface $metadata = null, $propertyPath, array $groups, $traversalStrategy, ExecutionContextInterface $context) public function validateNode($value, $valueHash, $container, $containerHash, MetadataInterface $metadata = null, $propertyPath, array $groups, $traversalStrategy, ExecutionContextInterface $context)
{ {
$context->setValue($value); $context->setNode($value, $metadata, $propertyPath);
$context->setMetadata($metadata);
$context->setPropertyPath($propertyPath);
// if group (=[<G1,G2>,G3,G4]) contains group sequence (=<G1,G2>) // if group (=[<G1,G2>,G3,G4]) contains group sequence (=<G1,G2>)
// then call traverse() with each entry of the group sequence and abort // then call traverse() with each entry of the group sequence and abort