BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
VirtualRESTServiceClient Class Reference
Collaboration diagram for VirtualRESTServiceClient:

Public Member Functions

 __construct (MultiHttpClient $http)
 
 mount ($prefix, $instance)
 
 unmount ($prefix)
 
 getMountAndService ($path)
 
 run (array $req)
 
 runMulti (array $reqs)
 

Public Attributes

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

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

Constructor & Destructor Documentation

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

Member Function Documentation

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
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
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
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
VirtualRESTServiceClient::unmount (   $prefix)

Unmap a prefix to service handler

Parameters
string$prefixVirtual path

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