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

Public Member Functions

 __construct ()
 setService ($restService)
 getService ()
 setEvent ($event)
 getEvent ()
 run ()

Data Fields

const ON_REQUEST_EVENT = 1
const ON_DATA_EVENT = 2
const ON_RENDER_EVENT = 3
const ON_ERROR_EVENT = 4

Private Attributes

 $_restService = null
 $_event = null

Detailed Description

WiseLoop RestTrigger class definition
This class provides means to execute some user actions when specific events happens.
To build a trigger the developer must extend wlRestTrigger class and overwrite the wlRestTrigger::run method.

class wlRestTriggerServiceKey extends wlRestTrigger {
    public function run() {
        //...
    }
}

To hook it up to a REST service, the trigger must be registered along with an event using wlRestService::registerTrigger method.

$service->registerTrigger(new wlRestTriggerServiceKey(), wlRestTrigger::ON_REQUEST_EVENT);
Author:
WiseLoop

Constructor & Destructor Documentation

__construct ( )

Member Function Documentation

getEvent ( )

Returns the event identifier to which the current trigger is hooked.

Returns:
int
getService ( )

Returns the REST service that has registered the current trigger.

Returns:
wlRestService
run ( )

Runs the current trigger.
This method should be overwritten in the derived class.

Reimplemented in wlRestTriggerAuth, wlRestTriggerAddTimestamp, wlRestTriggerAntiSpam, wlRestTriggerBanByIp, wlRestTriggerError, and wlRestTriggerServiceKey.

setEvent ( event)

Sets the event identifier to which the current trigger is hooked.

Parameters:
int$event
setService ( restService)

Sets the REST service that has registered the current trigger.

Parameters:
wlRestService$restService
Returns:
void

Field Documentation

$_event = null [private]

Type: int the event identifier to which the current trigger is hooked

$_restService = null [private]

Type: wlRestService the REST service that has registered the current trigger

const ON_DATA_EVENT = 2

ON_DATA_EVENT: occurs after the raw data is computed and retrieved, just before rendering and sendig it to the requester.
This event can be used to hook triggers that can do additional general processing of data before sending. A good example is the wlRestTriggerAddTimestamp trigger that simply adds a time stamp information to the data.

const ON_ERROR_EVENT = 4

ON_ERROR_EVENT: occurs when an exception is raised.
This event is used to hook triggers that formats the error message before sending it to the requester. Of course, the trigger can be used to mute any errors raised during the service call but this practice is not recommended. A good example (and it is highly recommended to be used) is wlRestTriggerError trigger that formats nicely the error message along with the error code and displays also the stack trace.

const ON_RENDER_EVENT = 3

ON_RENDER_EVENT: occurs after data is rendered with the corresponding output handler.
This event can be used to hook triggers that can do additional general formatting of data before sending. This event is quite seldom used as the main rendering of data is and should be done by the output handler.

const ON_REQUEST_EVENT = 1

ON_REQUEST_EVENT: occurs just before calling the service method, when the request is parsed.
This event can be used to hook triggers that can do various authentication procedures like session authentication or to implement an API service key validation.

 All Data Structures Functions Variables