Handle search with on timestamp

PHRAS-689
This commit is contained in:
Mathieu Darse
2015-11-10 18:36:29 +01:00
parent 5dc1fbe2cb
commit 0cd9933ac6
7 changed files with 92 additions and 6 deletions

View File

@@ -95,6 +95,9 @@ class QueryVisitor implements Visit
case NodeTypes::NATIVE_KEY:
return $this->visitNativeKeyNode($element);
case NodeTypes::TIMESTAMP_KEY:
return $this->visitTimestampKeyNode($element);
case NodeTypes::METADATA_KEY:
return new AST\KeyValue\MetadataKey($this->visitString($element));
@@ -297,10 +300,10 @@ class QueryVisitor implements Visit
});
}
private function visitNativeKeyNode(Element $element)
private function visitNativeKeyNode(TreeNode $node)
{
$this->assertChildrenCount($element, 1);
$type = $element->getChild(0)->getValue()['token'];
$this->assertChildrenCount($node, 1);
$type = $node->getChild(0)->getValue()['token'];
switch ($type) {
case NodeTypes::TOKEN_DATABASE:
return AST\KeyValue\NativeKey::database();
@@ -315,6 +318,20 @@ class QueryVisitor implements Visit
}
}
private function visitTimestampKeyNode(TreeNode $node)
{
$this->assertChildrenCount($node, 1);
$type = $node->getChild(0)->getValue()['token'];
switch ($type) {
case NodeTypes::TOKEN_CREATED_ON:
return AST\KeyValue\TimestampKey::createdOn();
case NodeTypes::TOKEN_UPDATED_ON:
return AST\KeyValue\TimestampKey::updatedOn();
default:
throw new InvalidArgumentException(sprintf('Unexpected token type "%s" for timestamp key.', $type));
}
}
private function assertChildrenCount(TreeNode $node, $count)
{
if ($node->getChildrenNumber() !== $count) {