waEvent

Event handling class

Contents...

This class is used by the framework for event handling.

Methods

  • __construct

    Class constructor.

  • addCustomHandler

    Links a dynamic event handler.

  • clearCache

    Clears event handlers data cache.

  • reset

    Clears event handlers runtime data.

  • run

    Triggers handlers for event passed to class constructor.

public function __construct ($app_id, $name, $options = array())

Class constructor. A class instance must be used to start handlers for a specified event by calling run() method.

Parameters

  • $app_id

    ID of an app whose event must be handled.

  • $name

    Event to be handled.

  • $options

    Special options. Supported keys and values are:

    • array_keys: array of keys of an array, which may be returned by an event handler, for which an empty string must be returned by default. If a specified event is declared in an app’s source code with a non-empty value of this parameter, then you must specify the same value when creating a waEvent class instance to trigger that event’s handlers—this is required to avoid errors in the use of results returned by handlers for such an event.

Example

//'frontend_product' event in 'shop' app is declared with array('menu', 'cart', 'block_aux', 'block') as the options value
//therefore, you must pass the same value for $options parameter to waEvent class constructor
$event = new waEvent('shop', 'frontend_product', array('menu', 'cart', 'block_aux', 'block'));

public static function addCustomHandler ($handler)

Links a dynamic event handler.

Parameters

  • $handler

    Event handler data as an array with the following keys and values:

    • event: event to be handled.
    • event_app_id: ID of an app whose event must be handled. If empty, then a specified event will be handled for all apps.
    • object: instance of a class whose public non-static method will be used as the event handler.
    • method: one event handling method name as a string, or multiple method names as an array of strings to be executed in the specified order.

Example

$handler = array(
    'object' => new someCustomClass(),
    'method' => 'eventHandler', //or array('eventHandler1', 'eventHandler2', ...)
    'event' => 'some_event',
    'event_app_id' => 'some_app',
);
waEvent::addCustomHandler($handler);

public static function clearCache()

Clears event handlers data cache stored in wa-cache/apps/system/waEvent/cache/ directory. Cache is saved if the debug mode is disabled and WA_EVENT_CLEAR_CACHE constant is not defined—you can define it in wa-config/SystemConfig.class.php file.

Example

waEvent::clearCache();

public static function reset()

Clears event handlers runtime data. This may be useful during development and debugging is event handlers data cache is not saved, i.e. when the debug mode is disabled and WA_EVENT_CLEAR_CACHE constant is not defined—you can define it in wa-config/SystemConfig.class.php file.

Example

waEvent::reset();

public function run (&$params = null)

Triggers handlers for an event passed to the class constructor.

Parameters

  • $params

    Parameters to be passed to event handlers.

Example

$event_class = new waEvent($event_app_id, $name, $options);
$result = $event_class->run($params);