Merge metadata & native key expressions

Do not delegates query building to Key instance anymore.
This commit is contained in:
Mathieu Darse
2015-11-05 16:52:01 +01:00
parent 803a9010a5
commit 713442c7b4
10 changed files with 70 additions and 194 deletions

View File

@@ -85,12 +85,6 @@ class QueryVisitor implements Visit
case NodeTypes::FIELD:
return new AST\Field($this->visitString($element));
case NodeTypes::METADATA_STATEMENT:
return $this->visitMetadataStatementNode($element);
case NodeTypes::METADATA_KEY:
return $this->visitMetadataKeyNode($element);
case NodeTypes::FLAG_STATEMENT:
return $this->visitFlagStatementNode($element);
@@ -98,11 +92,15 @@ class QueryVisitor implements Visit
return new AST\Flag($this->visitString($element));
case NodeTypes::NATIVE_KEY_VALUE:
return $this->visitNativeKeyValueNode($element);
case NodeTypes::METADATA_STATEMENT:
return $this->visitKeyValueNode($element);
case NodeTypes::NATIVE_KEY:
return $this->visitNativeKeyNode($element);
case NodeTypes::METADATA_KEY:
return $this->visitMetadataKeyNode($element);
default:
throw new Exception(sprintf('Unknown node type "%s".', $element->getId()));
}
@@ -315,17 +313,7 @@ class QueryVisitor implements Visit
return new AST\KeyValue\MetadataKey($name);
}
private function visitMetadataStatementNode(TreeNode $node)
{
if ($node->getChildrenNumber() !== 2) {
throw new Exception('Flag statement can only have 2 childs.');
}
$name = $this->visit($node->getChild(0));
$value = $this->visit($node->getChild(1));
return new AST\MetadataMatchStatement($name, $value);
}
private function visitNativeKeyValueNode(TreeNode $node)
private function visitKeyValueNode(TreeNode $node)
{
if ($node->getChildrenNumber() !== 2) {
throw new Exception('Key value expression can only have 2 childs.');