MediaWiki  1.28.0
VirtualRESTServiceClient Class Reference

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

Collaboration diagram for VirtualRESTServiceClient:

Public Member Functions

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

Public Attributes

const VALID_MOUNT_REGEX = '#^/[0-9a-z]+/([0-9a-z]+/)*$#'
 

Private Member Functions

 getInstance ($prefix)
 

Private Attributes

MultiHttpClient $http
 
array $instances = []
 Map of (prefix => VirtualRESTService|array) More...
 

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'.
Author
Aaron Schulz
Since
1.23

Definition at line 46 of file VirtualRESTServiceClient.php.

Constructor & Destructor Documentation

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

Definition at line 57 of file VirtualRESTServiceClient.php.

References $http, and http.

Member Function Documentation

VirtualRESTServiceClient::getInstance (   $prefix)
private
Parameters
string$prefix
Returns
VirtualRESTService

Definition at line 305 of file VirtualRESTServiceClient.php.

Referenced by getMountAndService(), and runMulti().

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 105 of file VirtualRESTServiceClient.php.

References $matches, $path, as, and getInstance().

Referenced by runMulti().

VirtualRESTServiceClient::mount (   $prefix,
  $instance 
)

Map a prefix to service handler.

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

Parameters
string$prefixVirtual path
VirtualRESTService | array$instanceService or info to yield the service

Definition at line 71 of file VirtualRESTServiceClient.php.

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:
    list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $client->run( $req );
    Parameters
    array$reqVirtual HTTP request maps
    Returns
    array Response array for request

Definition at line 145 of file VirtualRESTServiceClient.php.

References 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:
    list( $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 167 of file VirtualRESTServiceClient.php.

References $req, as, getInstance(), getMountAndService(), http, list, and use.

Referenced by run().

VirtualRESTServiceClient::unmount (   $prefix)

Unmap a prefix to service handler.

Parameters
string$prefixVirtual path

Definition at line 90 of file VirtualRESTServiceClient.php.

Member Data Documentation

MultiHttpClient VirtualRESTServiceClient::$http
private

Definition at line 48 of file VirtualRESTServiceClient.php.

Referenced by __construct().

array VirtualRESTServiceClient::$instances = []
private

Map of (prefix => VirtualRESTService|array)

Definition at line 50 of file VirtualRESTServiceClient.php.

const VirtualRESTServiceClient::VALID_MOUNT_REGEX = '#^/[0-9a-z]+/([0-9a-z]+/)*$#'

Definition at line 52 of file VirtualRESTServiceClient.php.


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