You are here

public function EasyRdf_Sparql_Client::listNamedGraphs in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Client.php \EasyRdf_Sparql_Client::listNamedGraphs()

Get a list of named graphs from a SPARQL 1.1 endpoint

Performs a SELECT query to get a list of the named graphs

Parameters

string $limit Optional limit to the number of results:

Return value

array Array of EasyRdf_Resource objects for each named graph

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Sparql/Client.php, line 152

Class

EasyRdf_Sparql_Client
Class for making SPARQL queries using the SPARQL 1.1 Protocol

Code

public function listNamedGraphs($limit = null) {
  $query = "SELECT DISTINCT ?g WHERE {GRAPH ?g {?s ?p ?o}}";
  if (!is_null($limit)) {
    $query .= " LIMIT " . (int) $limit;
  }
  $result = $this
    ->query($query);

  // Convert the result object into an array of resources
  $graphs = array();
  foreach ($result as $row) {
    array_push($graphs, $row->g);
  }
  return $graphs;
}