Skip to content
This repository was archived by the owner on Nov 12, 2023. It is now read-only.

PluginsUtil

Mic edited this page Oct 10, 2015 · 1 revision

If your plugin has a normal and an autoloaded version, you may need to define some functions only once and use them in both versions (ie: a datalayer access).

To achieve this goal, you can add the _util.php file to your plugin root folder.

This file must contain a class that extends the EvnPluginUtil abstract class setting the name as your plugin name (all lowercase!) and adding _util after it.

In this class you can define any function you need. This class can access the caller object using its caller property. So any plugin can use a util function, simply calling it this way:

$this->util->your_common_function_name($your_needed_args);

You can define any kind of functions inside the util class. The functions must be defined as public.

Example from the helloworld plugin.

class helloworld_util extends EvnPluginUtil
{
  public function common_function()
  {
    return 'This string has been generated by a common function, called by "'.$this->caller->get_name().'" plugin: it\'s defined once and can be used from the normal and the autoload versions of the plugin.';
  }
}

The function in our example is called, inside the activate() normal plugin method, with:

$this->util->common_function();

Clone this wiki locally