MediaWiki REL1_40
VirtualRESTServiceClient Class Reference

Virtual HTTP service client loosely styled after a Virtual File System. More...

Public Member Functions

 __construct (MultiHttpClient $http)
 
 getMountAndService ( $path)
 Get the prefix and service that a virtual path is serviced by.
 
 mount ( $prefix, $instance)
 Map a prefix to service handler.
 
 run (array $req)
 Execute a virtual HTTP(S) request.
 
 runMulti (array $reqs)
 Execute a set of virtual HTTP(S) requests concurrently.
 
 unmount ( $prefix)
 Unmap a prefix to service handler.
 

Detailed Description

Virtual HTTP service client loosely styled after a Virtual File System.

Services can be mounted on path prefixes so that virtual HTTP operations against sub-paths will map to those services. Operations can actually be done using HTTP messages over the wire or may simple be emulated locally.

Virtual HTTP request maps are arrays that use the following format:

  • method : GET/HEAD/PUT/POST/DELETE
  • url : HTTP/HTTPS URL or virtual service path with a registered prefix
  • query : <query parameter field/value associative array> (uses RFC 3986)
  • headers : <header name/value associative array>
  • body : source to get the HTTP request body from; this can simply be a string (always), a resource for PUT requests, and a field/value array for POST request; array bodies are encoded as multipart/form-data and strings use application/x-www-form-urlencoded (headers sent automatically)
  • stream : resource to stream the HTTP response body to Request maps can use integer index 0 instead of 'method' and 1 instead of 'url'.
Since
1.23

Definition at line 45 of file VirtualRESTServiceClient.php.

Constructor & Destructor Documentation

◆ __construct()

VirtualRESTServiceClient::__construct ( MultiHttpClient $http)
Parameters
MultiHttpClient$http

Definition at line 56 of file VirtualRESTServiceClient.php.

Member Function Documentation

◆ getMountAndService()

VirtualRESTServiceClient::getMountAndService ( $path)

Get the prefix and service that a virtual path is serviced by.

Parameters
string$path
Returns
array (prefix,VirtualRESTService) or (null,null) if none found

Definition at line 104 of file VirtualRESTServiceClient.php.

References $matches, and $path.

Referenced by runMulti().

◆ mount()

VirtualRESTServiceClient::mount ( $prefix,
$instance )

Map a prefix to service handler.

If $instance is in array, it must have these keys:

  • class : string; fully qualified VirtualRESTService class name
  • config : array; map of parameters that is the first __construct() argument
Parameters
string$prefixVirtual path
VirtualRESTService | array$instanceService or info to yield the service

Definition at line 70 of file VirtualRESTServiceClient.php.

◆ run()

VirtualRESTServiceClient::run ( array $req)

Execute a virtual HTTP(S) request.

This method returns a response map of:

  • code : HTTP response code or 0 if there was a serious cURL error
  • reason : HTTP response reason (empty if there was a serious cURL error)
  • headers : <header name/value associative array>
  • body : HTTP response body or resource (if "stream" was set)
  • error : Any cURL error string The map also stores integer-indexed copies of these values. This lets callers do:
    [ $rcode, $rdesc, $rhdrs, $rbody, $rerr ] = $client->run( $req );
    Parameters
    array$reqVirtual HTTP request maps
    Returns
    array Response array for request

Definition at line 141 of file VirtualRESTServiceClient.php.

References runMulti().

◆ runMulti()

VirtualRESTServiceClient::runMulti ( array $reqs)

Execute a set of virtual HTTP(S) requests concurrently.

A map of requests keys to response maps is returned. Each response map has:

  • code : HTTP response code or 0 if there was a serious cURL error
  • reason : HTTP response reason (empty if there was a serious cURL error)
  • headers : <header name/value associative array>
  • body : HTTP response body or resource (if "stream" was set)
  • error : Any cURL error string The map also stores integer-indexed copies of these values. This lets callers do:
    [ $rcode, $rdesc, $rhdrs, $rbody, $rerr ] = $responses[0];
Parameters
array[]$reqsMap of Virtual HTTP request maps
Returns
array $reqs Map of corresponding response values with the same keys/order
Exceptions
Exception

Definition at line 163 of file VirtualRESTServiceClient.php.

References getMountAndService(), PROTO_CURRENT, and wfExpandUrl().

Referenced by run().

◆ unmount()

VirtualRESTServiceClient::unmount ( $prefix)

Unmap a prefix to service handler.

Parameters
string$prefixVirtual path

Definition at line 89 of file VirtualRESTServiceClient.php.


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