Plugins

SyDES use plugins to modify the data during operation of the modules, as well as to add additional actions, without interfering with the code of the modules. For example, they can be used to implement processing shortcodes in the content or send SMS when filling a specific form.

Each plugin or a set of plugins, united by a common goal, must be into a separate php file in folder system/plugin.

Initialization code quite simple

<?php
$app->on('event', 'routes', function() use ($app){
    // do somerhing
}, 0);

Где

  • event - a specific event in the application
  • routes - limiting the effect by the routes
  • $app - application
  • 0 - execution priority, optional

Events

At the moment, SyDES has only 3 events

  • after.bootstrap - after the system has collected all the data, setted up the environment, and loaded the required library
  • before.module - before starting module
  • after.module - after the module has worked and placed data in the registry

Also, when creating their modules, you can register own events.

$app->trigger('myevent', array('question?', '42'));

where

  • myevent - a unique key for the event. May contain the name of the module and the name of the event, such as before.myevent.mymodule
  • array - an optional array of data that may be needed for the plugin.

If passed an array, then the plugin code can be used, by adding to function() variables that are filled in order of priority

$app->on('myevent', 'question/*', function($q, $a) use ($app){
	$app->request->get['answer'] = $q . ' ' . $a . ' is answer';
});

Routes

You can specify either the full path, and with the support of wildcard.

Examples:

  • * - any request to an application
  • pages/* - any action of pages module
  • */save - saving in any module
  • pages/view/42 - view page with id = 42
  • constructors/form/send - filling in the form in constructors

Application

The $app variable is contains access to registry and core methods

Priority

If you do not specify a priority, it will be equal to 0 and those plugins will run in the order of their detection.

If the plugin returns false, all subsequent plugin in the current event will not be executed.




If you want to know something further - ask in the comments. The documentation will be complemented by your questions.
© Arthur Grand, 2011–2021
Powered by SyDES