/** * 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; }
/** * Adds the given subquery. * * @param QueryBuilder $queryBuilder * @return self * @throws InvalidArgumentException */ public function subquery(QueryBuilder $queryBuilder) { $this->subqueries[] = $queryBuilder->getSPARQL(false); $this->usageValidator->trackDefinedVariables(implode(' ', $queryBuilder->getSelects())); // @todo temp hack to add AS definitions to defined variables $regexHelper = new RegexHelper(); $matches = $regexHelper->getMatches('AS \\{variable}', implode(' ', $queryBuilder->getSelects())); $this->usageValidator->trackDefinedVariables($matches); return $this; }
private function matchPrefixes($expression) { return $this->regexHelper->getMatches('(^|\\W)(\\{prefix}):\\{name}', $expression, 2); }
/** * @dataProvider provideGetMatches */ public function testGetMatches($regex, $expression, $matches) { $regexHelper = new RegexHelper(); $this->assertEquals($matches, $regexHelper->getMatches($regex, $expression)); }
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; } }