/**
  * @dataProvider provideTrackPrefixesParsing
  */
 public function testTrackPrefixesParsing($input, $expected)
 {
     $usageValidator = new UsageValidator();
     $usageValidator->trackUsedPrefixes($input);
     $this->setExpectedException('RangeException', $expected);
     $usageValidator->validate();
 }
 /**
  * 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));
 }
Exemple #3
0
 /**
  * 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;
 }
Exemple #4
0
 /**
  * Returns the plain SPARQL string of this query.
  *
  * @param bool $includePrefixes
  * @return string
  * @throws InvalidArgumentException
  * @throws RangeException
  */
 public function getSPARQL($includePrefixes = true)
 {
     if (!is_bool($includePrefixes)) {
         throw new InvalidArgumentException('$includePrefixes has to be a bool');
     }
     $this->usageValidator->validate();
     $sparql = $includePrefixes ? $this->prefixBuilder->getSPARQL() : '';
     $sparql .= 'SELECT ' . $this->uniqueness . $this->formatSelects() . ' WHERE';
     $sparql .= ' {' . $this->graphBuilder->getSPARQL() . ' }';
     $sparql .= $this->modifierBuilder->getSPARQL();
     return $sparql;
 }