MediaWiki REL1_32
MediaWiki\Sparql\SparqlClient Class Reference

Simple SPARQL client. More...

Collaboration diagram for MediaWiki\Sparql\SparqlClient:

Public Member Functions

 __construct ( $url, HttpRequestFactory $requestFactory)
 
 appendUserAgent ( $agent)
 Append specific string to user agent.
 
 getUserAgent ()
 Get current user agent.
 
 query ( $sparql, $rawData=false)
 Query SPARQL endpoint.
 
 setClientOptions ( $options)
 Set client options.
 
 setTimeout ( $timeout)
 Set query timeout (in seconds)
 
 setUserAgent ( $agent)
 Set user agent string.
 

Public Attributes

const MAX_GET_SIZE = 2048
 Limit on how long can be the query to be sent by GET.
 

Private Member Functions

 extractData ( $data, $rawData=false)
 Extract data from SPARQL response format.
 

Private Attributes

string $endpoint
 SPARQL endpoint URL.
 
array $options = []
 Client options.
 
HttpRequestFactory $requestFactory
 
int $timeout = 30
 Query timeout (seconds)
 
string $userAgent
 User agent for HTTP requests.
 

Detailed Description

Simple SPARQL client.

Author
Stas Malyshev

Definition at line 31 of file SparqlClient.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Sparql\SparqlClient::__construct (   $url,
HttpRequestFactory  $requestFactory 
)
Parameters
string$urlSPARQL Endpoint
HttpRequestFactory$requestFactory

Definition at line 71 of file SparqlClient.php.

References MediaWiki\Sparql\SparqlClient\$requestFactory, and Http\userAgent().

Member Function Documentation

◆ appendUserAgent()

MediaWiki\Sparql\SparqlClient::appendUserAgent (   $agent)

Append specific string to user agent.

This is the recommended way of specifying the user agent for specific applications of the SparqlClient inside MediaWiki and extension code.

Parameters
string$agent

Definition at line 129 of file SparqlClient.php.

◆ extractData()

MediaWiki\Sparql\SparqlClient::extractData (   $data,
  $rawData = false 
)
private

Extract data from SPARQL response format.

The response must be in format described in: https://www.w3.org/TR/sparql11-results-json/

Parameters
array$dataSPARQL result
bool$rawDataWhether to return only values or full data objects
Returns
array List of results, one row per element.

Definition at line 197 of file SparqlClient.php.

References $vars, and as.

Referenced by MediaWiki\Sparql\SparqlClient\query().

◆ getUserAgent()

MediaWiki\Sparql\SparqlClient::getUserAgent ( )

Get current user agent.

Returns
string

Definition at line 103 of file SparqlClient.php.

References MediaWiki\Sparql\SparqlClient\$userAgent.

◆ query()

MediaWiki\Sparql\SparqlClient::query (   $sparql,
  $rawData = false 
)

Query SPARQL endpoint.

Parameters
string$sparqlquery
bool$rawDataWhether to return only values or full data objects
Returns
array List of results, one row per array element Each row will contain fields indexed by variable name.
Exceptions
SparqlException

Definition at line 143 of file SparqlClient.php.

References MediaWiki\Sparql\SparqlClient\$options, $request, MediaWiki\Sparql\SparqlClient\$timeout, MediaWiki\Sparql\SparqlClient\$userAgent, MediaWiki\Sparql\SparqlClient\extractData(), options(), and wfAppendQuery().

◆ setClientOptions()

MediaWiki\Sparql\SparqlClient::setClientOptions (   $options)

Set client options.

Parameters
array$options
Returns
$this

Definition at line 94 of file SparqlClient.php.

References MediaWiki\Sparql\SparqlClient\$options, and options().

◆ setTimeout()

MediaWiki\Sparql\SparqlClient::setTimeout (   $timeout)

Set query timeout (in seconds)

Parameters
int$timeout
Returns
$this

Definition at line 82 of file SparqlClient.php.

References MediaWiki\Sparql\SparqlClient\$timeout.

◆ setUserAgent()

MediaWiki\Sparql\SparqlClient::setUserAgent (   $agent)

Set user agent string.

Mote it is not recommended to completely override user agent for most applications.

See also
appendUserAgent() for recommended way of specifying user agent.
Parameters
string$agent

Definition at line 116 of file SparqlClient.php.

Member Data Documentation

◆ $endpoint

string MediaWiki\Sparql\SparqlClient::$endpoint
private

SPARQL endpoint URL.

Definition at line 54 of file SparqlClient.php.

◆ $options

array MediaWiki\Sparql\SparqlClient::$options = []
private

Client options.

Definition at line 60 of file SparqlClient.php.

Referenced by MediaWiki\Sparql\SparqlClient\query(), and MediaWiki\Sparql\SparqlClient\setClientOptions().

◆ $requestFactory

HttpRequestFactory MediaWiki\Sparql\SparqlClient::$requestFactory
private

Definition at line 65 of file SparqlClient.php.

Referenced by MediaWiki\Sparql\SparqlClient\__construct().

◆ $timeout

int MediaWiki\Sparql\SparqlClient::$timeout = 30
private

Query timeout (seconds)

Definition at line 48 of file SparqlClient.php.

Referenced by MediaWiki\Sparql\SparqlClient\query(), and MediaWiki\Sparql\SparqlClient\setTimeout().

◆ $userAgent

string MediaWiki\Sparql\SparqlClient::$userAgent
private

User agent for HTTP requests.

Definition at line 42 of file SparqlClient.php.

Referenced by MediaWiki\Sparql\SparqlClient\getUserAgent(), and MediaWiki\Sparql\SparqlClient\query().

◆ MAX_GET_SIZE

const MediaWiki\Sparql\SparqlClient::MAX_GET_SIZE = 2048

Limit on how long can be the query to be sent by GET.

Definition at line 36 of file SparqlClient.php.

Referenced by MediaWiki\Sparql\SparqlClientTest\optionsProvider().


The documentation for this class was generated from the following file: