/** * {@inheritdoc} */ public function __invoke(Record $record) { if (!isset($this->ast)) { $tokens = ExpressionParser::lex($this->expr, $this->vars); $this->ast = ExpressionParser::parseExpression($tokens); } return $this->ast->__invoke($record); }
/** * {@inheritdoc} */ public function __invoke(array $data) { if (!isset($this->ast)) { $tokens = ExpressionParser::lex($this->expr, $this->vars); $this->ast = ExpressionParser::parseExpression($tokens); } return $this->ast->__invoke($data); }
public function testParseExpression() { $ast = ExpressionParser::parseExpression(ExpressionParser::lex('3 = 3')); $this->assertInstanceOf('Jivoo\\Data\\Query\\Expression\\Infix', $ast); $this->assertInstanceOf('Jivoo\\Data\\Query\\Expression\\Literal', $ast->left); $this->assertInstanceOf('Jivoo\\Data\\Query\\Expression\\Literal', $ast->right); $this->assertEquals('=', $ast->operator); $ast = ExpressionParser::parseExpression(ExpressionParser::lex('not 3 = 3')); $this->assertInstanceOf('Jivoo\\Data\\Query\\Expression\\Prefix', $ast); $this->assertInstanceOf('Jivoo\\Data\\Query\\Expression\\Infix', $ast->operand); $this->assertEquals('not', $ast->operator); $ast = ExpressionParser::parseExpression(ExpressionParser::lex('not a in %e', array($ast))); $this->assertInstanceOf('Jivoo\\Data\\Query\\Expression\\Prefix', $ast); $this->assertInstanceOf('Jivoo\\Data\\Query\\Expression\\Infix', $ast->operand); $this->assertEquals('not', $ast->operator); }