-
Notifications
You must be signed in to change notification settings - Fork 28
Creating Plugins
Making plugins for Limelight is simple. First, create a plugin class and have it extend Limelight\Plugins\Plugin. Limelight\Plugins\Plugin has one abstract method, handle(), which you must implement.
use Limelight\Plugins\Plugin;
class Example extends Plugin
{
public function handle()
{
}
}
If you need to use a constructor, be sure to pass the arguments up to the parent.
public function __construct($text, $node, $tokens, $words)
{
parent::__construct($text, $node, $tokens, $words);
// Construct what you need
}
Note: A plugin template with some example code can be found in Limelight/Plugins.
The parent object has the following properties on it:
- $text - The original, user inputed text.
- $node - An instance of Limelight\Mecab\Node which can be used to gain access to the raw MeCab information.
- $tokens - An array of information gained from the MeCab nodes.
- $words - An array of LimelightWord objects.
To get config data, make a config instance and the get() method.
$config = Config::getInstance();
$options = $config->get('PluginName');
After gaining what data you need, set the data on an individual LimelightWord instance with the setPluginData() method, passing through the name of your plugin and the data.
$word->setPluginData('PluginName', $data);
To set data on the LimelightResults object, return the data from your plugin class.
return $data;
Data that is stored on either the LimelightResults object or the LimelightWord object can be accessed via the plugin() method.
Get plugin data off the LimelightResults object.
$results->plugin('PluginName');
Get plugin data off the LimelightWord object in the same way.
$word->plugin('PluginName');