/**
  * Sets the prefixes for the given IRIs.
  *
  * @param string[] $prefixes
  * @throws InvalidArgumentException
  */
 private function setPrefixes(array $prefixes)
 {
     foreach ($prefixes as $prefix => $iri) {
         $this->expressionValidator->validate($prefix, ExpressionValidator::VALIDATE_PREFIX);
         $this->expressionValidator->validate($iri, ExpressionValidator::VALIDATE_IRI);
         $this->prefixes[$prefix] = $iri;
     }
     $this->usageValidator->trackDefinedPrefixes(array_keys($this->prefixes));
 }
Beispiel #2
0
 /**
  * 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;
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 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;
     }
 }
 public function testValidate_invalidArgument()
 {
     $expressionValidator = new ExpressionValidator();
     $this->setExpectedException('InvalidArgumentException');
     $expressionValidator->validate(null, ExpressionValidator::VALIDATE_ALL);
 }