You are here

protected function EasyRdf_GraphStore::sendGraph in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/GraphStore.php \EasyRdf_GraphStore::sendGraph()

Send some graph data to the graph store

This method is used by insert() and replace()

@ignore

2 calls to EasyRdf_GraphStore::sendGraph()
EasyRdf_GraphStore::insert in vendor/easyrdf/easyrdf/lib/EasyRdf/GraphStore.php
Add data to a graph in the graph store
EasyRdf_GraphStore::replace in vendor/easyrdf/easyrdf/lib/EasyRdf/GraphStore.php
Replace the contents of a graph in the graph store with new data

File

vendor/easyrdf/easyrdf/lib/EasyRdf/GraphStore.php, line 117

Class

EasyRdf_GraphStore
A class for fetching, saving and deleting graphs to a Graph Store. Implementation of the SPARQL 1.1 Graph Store HTTP Protocol.

Code

protected function sendGraph($method, $graph, $uriRef, $format) {
  if (is_object($graph) and $graph instanceof EasyRdf_Graph) {
    if ($uriRef === null) {
      $uriRef = $graph
        ->getUri();
    }
    $data = $graph
      ->serialise($format);
  }
  else {
    $data = $graph;
  }
  if ($uriRef === null) {
    throw new InvalidArgumentException('Graph IRI is not specified');
  }
  $formatObj = EasyRdf_Format::getFormat($format);
  $mimeType = $formatObj
    ->getDefaultMimeType();
  if ($uriRef === self::DEFAULT_GRAPH) {
    $dataUrl = $this
      ->urlForGraph(self::DEFAULT_GRAPH);
  }
  else {
    $graphUri = $this->parsedUri
      ->resolve($uriRef)
      ->toString();
    $dataUrl = $this
      ->urlForGraph($graphUri);
  }
  $client = EasyRdf_Http::getDefaultHttpClient();
  $client
    ->resetParameters(true);
  $client
    ->setUri($dataUrl);
  $client
    ->setMethod($method);
  $client
    ->setRawData($data);
  $client
    ->setHeaders('Content-Type', $mimeType);
  $response = $client
    ->request();
  if (!$response
    ->isSuccessful()) {
    throw new EasyRdf_Exception("HTTP request for {$dataUrl} failed: " . $response
      ->getMessage());
  }
  return $response;
}