Your cart is empty!
Start Framework
public function onStartVikRestaurantsAPI( API &$api ) : void
Fires while starting the API framework.
Description
Trigger hook to let the plugins alter the application framework. It is possible to use this hook to include third-party applications.
In order to extend the list of supported plugins/applications, you need to attach your classes to the $api
object, which can be done through the code below.
$api->registerEventProvider('test_plugin', function(string $event, array $options) {
require_once dirname(__FILE__) . '/plugins/TestPluginEvent.php';
return new TestPluginEvent($event, $options);
});
The registered events must inherit the E4J\VikRestaurants\API\Event
class, otherwise they will be ignored.
Parameters
- &$api
-
(API) The framework API instance. This class is part of the
E4J\VikRestaurants\API
namespace.
Return Value
None.
Example
The example below explains how to support a custom API event.
/**
* Trigger event to let the plugins alter the API framework.
* It is possible to use this event to include third-party applications.
*
* @param E4J\VikRestaurants\API\API &$api
*
* @return void
*
* @since 1.9
*/
public function onStartVikRestaurantsAPI(&$api)
{
// register "test_plugin" API event
$api->registerEventProvider('test_plugin', function(string $event, array $options) {
// anonymous classes are supported too, but still need to inherit the Event class
return new class ($event, $options) extends E4J\VikRestaurants\API\Event {
/**
* @inheritDoc
*/
public function getTitle()
{
return 'Test Plugin';
}
/**
* @inheritDoc
*/
public function getShortDescription()
{
return 'Testing the implementation of a custom event for the VikRestaurants API framework.';
}
/**
* @inheritDoc
*/
protected function execute(array $args, Response $response)
{
/**
* @todo do stuff here
*/
}
};
});
}
Changelog
Version | Description |
---|---|
1.9 | Introduced. |
Last Update: 2023-12-29 14:15
Helpful?