WiseLoop PHP REST Services 3.3.1
RESTful web service API framework for PHP
wlRestOutputHandler Class Reference
Inheritance diagram for wlRestOutputHandler:

Public Member Functions

 __construct ($extensions)
 getExtensions ()
 render ($data)
 getContentType ()

Private Attributes


Detailed Description

WiseLoop RestOutputHandler class definition
This class provides the mechanism to output the service returned data.
An output handler is responsible to transform and render the data according to a desired format and it should also provide the content mime type format that will be sent to the requester. A REST service can register more output handlers to work with, the one used to render the data will be choosen by matching the extension of the request URL with the extensions provided at registering time; so, the extension acts like a key to identify the proper output handler.
For example the URL http ://rest-service-url-endpoint/resource/99.json will return the data in JSON format (if an output handler with .json extension is registered into the service)
To build a custom output handler the developer must extend wlRestOutputHandler class and overwrite two methods: wlRestOutputHandler::render and wlRestOutputHandler::getContentType.

class csvSampleOutputHandler extends wlRestOutputHandler {
    public function render($data) {
    public function getContentType() {

To make it available for a REST service, the custom output handler must be registered along with the extensions using wlRestService::registerOutputHandler.

 $service->registerOutputHandler(new csvSampleOutputHandler(array('csv', 'sv')));
See also:

Constructor & Destructor Documentation

__construct ( extensions)

Creates a wlRestOutputHandler object.
In order to associate more than one extension to the output handler, an array of strings representing the extensions can be provided to the constructor.

string | array$extensionsthe extensions associated with this output handler

Member Function Documentation

getContentType ( )

This method provides the content mime type information that will be sent in the header along with the data.
It should consist of a single line of code returning the content type string.
The default value is 'text/html', so for a custom output handler this method should be overwritten in the derived class if the content type is different from 'text/html'.

string the content mime type header that will be sent to the requester

Reimplemented in wlRestOutputHandlerJson, and wlRestOutputHandlerXml.

getExtensions ( )

Returns the associated extensions with this output handler.

array the output handler associated extensions
render ( data)

This method is responsible to process the passed data and format it as desired before the REST service will send it to the requester.
When creating custom output handlers, this method needs to be ovewritten in the derived class.

mixed the processed data to be sent to the requester

Reimplemented in wlRestOutputHandlerArray, wlRestOutputHandlerJson, wlRestOutputHandlerPhp, wlRestOutputHandlerPlain, and wlRestOutputHandlerXml.

Field Documentation

$_extensions [private]

Type: array the extensions associated with this output handler

 All Data Structures Functions Variables