/** * Specifies the expressions to select. * * @param string|string[] $expressions * @return self * @throws InvalidArgumentException */ public function select($expressions) { $expressions = is_array($expressions) ? $expressions : func_get_args(); foreach ($expressions as $expression) { $this->expressionValidator->validate($expression, ExpressionValidator::VALIDATE_VARIABLE | ExpressionValidator::VALIDATE_FUNCTION_AS); // @todo temp hack to add AS definitions to defined variables $regexHelper = new RegexHelper(); $matches = $regexHelper->getMatches('AS \\{variable}', $expression); $this->usageValidator->trackDefinedVariables($matches); // @todo detect functions and wrap with brackets automatically $this->usageValidator->trackUsedVariables($expression); $this->selects[] = $expression; } return $this; }
/** * @dataProvider provideTrackVariablesParsing */ public function testTrackVariablesParsing($input, $expected) { $usageValidator = new UsageValidator(); $usageValidator->trackUsedVariables($input); $this->setExpectedException('RangeException', $expected); $usageValidator->validate(); }
/** * Adds the given expression as a filter to this query. * * @param string $expression * @return self * @throws InvalidArgumentException */ public function filter($expression) { $this->expressionValidator->validate($expression, ExpressionValidator::VALIDATE_FUNCTION); $this->usageValidator->trackUsedPrefixes($expression); $this->usageValidator->trackUsedVariables($expression); $this->filters[] = '(' . $expression . ')'; return $this; }
private function addExpressions(array $expressions, $options = null) { foreach ($expressions as $expression) { $this->expressionValidator->validate($expression, $options ?: ExpressionValidator::VALIDATE_VARIABLE | ExpressionValidator::VALIDATE_FUNCTION_AS); // @todo temp hack to add AS definitions to defined variables $regexHelper = new RegexHelper(); $matches = $regexHelper->getMatches('AS \\{variable}', $expression); $this->usageValidator->trackDefinedVariables($matches); // @todo detect functions and wrap with brackets automatically $this->usageValidator->trackUsedVariables($expression); $this->usageValidator->trackUsedPrefixes($expression); $this->selects[] = $expression; } }