WiseLoop PHP REST Services 3.3.1
RESTful web service API framework for PHP
wlRestRequest Class Reference

Public Member Functions

 __construct ($urlRouteFormat)
 parse ($urlRouteFormat)
 getActionParams ()
 getExtension ()
 getMethod ()
 getParam ($key)
 getControllerName ()
 getControllerVersion ()
 getControllerAction ()
 getRemoteAddress ()
 getRemoteHost ()
 getUserAgent ()
 getUri ()

Data Fields

const REQUEST_METHOD_GET = 'GET'
const REQUEST_METHOD_POST = 'POST'
const REQUEST_METHOD_PUT = 'PUT'
const REQUEST_METHOD_DELETE = 'DELETE'

Private Member Functions

 computePathInfo ()
 computeExtension ($pathInfo)
 computeRequestMethod ()
 getPutPayload ()

Private Attributes

 $_extension = null
 $_params = null
 $_method = null
 $_actionParams = null
 $_cachedPutInfo = null

Detailed Description

WiseLoop RestRequest class definition
This class is responsible to parse and hold the request information submited by a data consumer through the URL.
The request object determines and holds the following information:

  • the request method: can be GET, POST, PUT or DELETE;
  • the request extension: is a string preceded by dot and it will be used to determine the output handler for rendering the data;
  • service controller name: retrieved from the URL, it will be used to instantiate a registered controller in order to call the required service action;
  • service controller version: retrieved from the URL, it represents the service controller version to be used when calling an action;
  • service controller action name: retrieved from the URL, it represents the actual controller method name that will be called to provide the requested data;
  • action parameters: these parameters are retrieved from PUT and POST submitted data;
  • an array of query (GET) parameters: this piece of information is retrieved from the URL and will consist of some (key/value) pairs according to the URL format;
    The URL route format provided in the constructor represents the keys and it is used to parse and compute the actual GET parameters values given in the URL.
    For example, if we have a route like key1/key2/key3, after submitting http ://rest-service-url-endpoint/abc/some-value/99, the query array will have: ('key1'=>'abc', 'key2'=>'some-value', 'key3'=>'99').
    A more realistic example is the default route format given in the default rest-settings.ini settings file: route=controller/version/action. In this case, after submitting http ://rest-service-url-endpoint/math/v1/add/1/2/3/4, the query array will have: ('controller'=>'math', 'version'='v1', 'action'=>'add'). The values to be added (1, 2, 3, 4) are available when calling wlRestRequest::getQueryParams method.
    Author:
    WiseLoop

Constructor & Destructor Documentation

__construct ( urlRouteFormat)

Constructor.
Creates a wlRestRequest object.

Parameters:
string$urlRouteFormat

Member Function Documentation

computeExtension ( pathInfo) [private]

Returns the URL extension used to instantiate the proper output handler.

Parameters:
string$pathInfothe parsed pathinfo as returned by wlRestRequest::computePathInfo
Returns:
string
See also:
wlRestRequest::computePathInfo
computePathInfo ( ) [private]

Returns a parsed pathinfo from the request full URL containing only the relevant information for determining the service controller name, version, action and other query (GET) parameters.

Returns:
string
computeRequestMethod ( ) [private]

Returns the request method.

Returns:
string
getActionParams ( )

Returns the data submitted through requests (payload).

Returns:
mixed|null
getControllerAction ( )

Returns the service controller action. It represents the actual controller method name that will be called to provide the requested data.
The service controller action is identified by the action key as defined by the default route format in rest-settings.ini file. The developer should not give a different meaning to this key by overwriting (using) it in another settings file.

See also:
wlRestUtils::ROUTE_ACTION
Returns:
string
getControllerName ( )

Returns the service controller name. It will be used to instantiate a registered controller in order to call the required service action.
The service controller name is identified by the controller key as defined by the default route format in rest-settings.ini file. The developer should not give a different meaning to this key by overwriting (using) it in another settings file.

Returns:
string
See also:
wlRestUtils::ROUTE_CONTROLLER
getControllerVersion ( )

Returns the service controller version. It represents the service controller version to be used when calling an action.
The service controller version is identified by the version key as defined by the default route format in rest-settings.ini file. The developer should not give a different meaning to this key by overwriting (using) it in another settings file.

See also:
wlRestUtils::ROUTE_VERSION
Returns:
string
getExtension ( )

Returns the URL extension; this will be used to determine the output handler for rendering the data.

Returns:
string
getMethod ( )

Returns the request method (GET, POST, PUT or DELETE)

Returns:
string
getParam ( key)

Returns the URL parameter for a specified key as defined in the route format.

Parameters:
string$key
Returns:
string
getPutPayload ( ) [private]

Returns the passed data through PUT request. It needs to be cached as it is read from a stream and it will become unavailable after the first read.

Returns:
mixed
getRemoteAddress ( )

Returns the IP address of the requester.

Returns:
string
getRemoteHost ( )

Returns the hostname of the requester or null if not available.

Returns:
string|null
getUri ( )

Returns the request full URL.

Returns:
string
getUserAgent ( )

Returns the user agent of the requester or null if not available.

Returns:
string|null
parse ( urlRouteFormat)

Parses the given URL route format against the actual URL.

Parameters:
array$urlRouteFormat
Exceptions:
wlRestException

Field Documentation

$_actionParams = null [private]

Type: mixed data submitted through requests (payload)

$_cachedPutInfo = null [private]

Type: mixed data submitted through PUT requests

$_extension = null [private]

Type: string the URL extension - will be used to determine the output handler for rendering the data

$_method = null [private]
$_params = null [private]

Type: array the full query (GET) parameters (key/value pairs) according to the route format

const REQUEST_METHOD_DELETE = 'DELETE'
const REQUEST_METHOD_GET = 'GET'
const REQUEST_METHOD_POST = 'POST'
const REQUEST_METHOD_PUT = 'PUT'
 All Data Structures Functions Variables