Skip to content

Commit

Permalink
Merge pull request #19 from Mech7/describe
Browse files Browse the repository at this point in the history
Add describe method
  • Loading branch information
Benestar committed Sep 29, 2015
2 parents 11c79cd + a81378e commit e08d746
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/QueryBuilder.php
Expand Up @@ -17,7 +17,24 @@
* @author Bene* < benestar.wikimedia@gmail.com >
*/
class QueryBuilder {


/**
* Select query
*/
CONST TYPE_SELECT = 'SELECT';

/**
* Describe query
*/
CONST TYPE_DESCRIBE = 'DESCRIBE';

/**
* Current type defaults to select)
*
* @var string
*/
private $currentType = self::TYPE_SELECT;

/**
* @var ExpressionValidator
*/
Expand Down Expand Up @@ -74,6 +91,18 @@ public function getSelects() {
return $this->selects;
}

/**
* Specifies the expressions to describe.
*
* @param string|string[] $expressions
* @return self
* @throws InvalidArgumentException
*/
public function describe($expressions) {
$this->currentType = self::TYPE_DESCRIBE;
return $this->select($expressions);
}

/**
* Specifies the expressions to select.
*
Expand Down Expand Up @@ -102,7 +131,7 @@ public function select( $expressions /* expressions ... */ ) {
return $this;
}

/**
/**
* Specifies the expressions to select. Duplicate results are eliminated.
*
* @since 0.3
Expand Down Expand Up @@ -348,7 +377,7 @@ public function getSPARQL( $includePrefixes = true ) {
$this->usageValidator->validate();

$sparql = $includePrefixes ? $this->prefixBuilder->getSPARQL() : '';
$sparql .= 'SELECT ' . $this->uniqueness . $this->formatSelects() . ' WHERE';
$sparql .= $this->currentType . ' ' . $this->uniqueness . $this->formatSelects() . ' WHERE';
$sparql .= ' {' . $this->graphBuilder->getSPARQL() . ' }';
$sparql .= $this->modifierBuilder->getSPARQL();

Expand Down

0 comments on commit e08d746

Please sign in to comment.