MediaWiki REL1_33
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.
 
 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.
 

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)
 

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.

References http.

Member Function Documentation

◆ getInstance()

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

Definition at line 301 of file VirtualRESTServiceClient.php.

Referenced by getMountAndService(), and runMulti().

◆ 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, $path, as, getInstance(), and null.

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:
    list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $client->run( $req );
    deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
    Definition deferred.txt:11
    this hook is for auditing only $req
    Definition hooks.txt:979
    Parameters
    array$reqVirtual HTTP request maps
    Returns
    array Response array for request

Definition at line 141 of file VirtualRESTServiceClient.php.

References $req, and 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:
    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 163 of file VirtualRESTServiceClient.php.

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

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.

Member Data Documentation

◆ $http

MultiHttpClient VirtualRESTServiceClient::$http
private

Definition at line 47 of file VirtualRESTServiceClient.php.

◆ $instances

array VirtualRESTServiceClient::$instances = []
private

Map of (prefix => VirtualRESTService|array)

Definition at line 49 of file VirtualRESTServiceClient.php.

◆ VALID_MOUNT_REGEX

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

Definition at line 51 of file VirtualRESTServiceClient.php.


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