public function testPublicAccess() { $instance = new RepositoryClient('Foo', 'Bar', 'Nu', 'Vim'); $this->assertSame('Foo', $instance->getDefaultGraph()); $this->assertSame('Bar', $instance->getQueryEndpoint()); $this->assertSame('Nu', $instance->getUpdateEndpoint()); $this->assertSame('Vim', $instance->getDataEndpoint()); }
/** * Execute a HTTP-based SPARQL POST request according to * http://www.w3.org/2009/sparql/docs/http-rdf-update/. * The method throws exceptions based on * GenericHttpDatabaseConnector::mapHttpRequestError(). If errors occur and this * method does not throw anything, then an empty result with an error * code is returned. * * @note This protocol is not part of the SPARQL standard and may not * be supported by all stores. To avoid using it, simply do not provide * a data endpoint URL when configuring the SPARQL database. If used, * the protocol might lead to a better performance since there is less * parsing required to fetch the data from the request. * @note Some stores (e.g. 4Store) support another mode of posting data * that may be implemented in a special database handler. * * @param $payload string Turtle serialization of data to send * * @return boolean */ public function doHttpPost($payload) { if ($this->repositoryClient->getDataEndpoint() === '') { throw new BadHttpDatabaseResponseException(BadHttpDatabaseResponseException::ERROR_NOSERVICE, "SPARQL POST with data: {$payload}", 'not specified'); } $defaultGraph = $this->repositoryClient->getDefaultGraph(); $this->httpRequest->setOption(CURLOPT_URL, $this->repositoryClient->getDataEndpoint() . ($defaultGraph !== '' ? '?graph=' . urlencode($defaultGraph) : '?default')); $this->httpRequest->setOption(CURLOPT_POST, true); // POST as file (fails in 4Store) $payloadFile = tmpfile(); fwrite($payloadFile, $payload); fseek($payloadFile, 0); $this->httpRequest->setOption(CURLOPT_INFILE, $payloadFile); $this->httpRequest->setOption(CURLOPT_INFILESIZE, strlen($payload)); $this->httpRequest->setOption(CURLOPT_HTTPHEADER, array('Content-Type: application/x-turtle')); $this->httpRequest->execute(); if ($this->httpRequest->getLastErrorCode() == 0) { return true; } // TODO The error reporting based on SPARQL (Update) is not adequate for the HTTP POST protocol $this->mapHttpRequestError($this->repositoryClient->getDataEndpoint(), $payload); return false; }