noccylabs/plugin

$ git tag
0.1.0
0.1.1
0.1.2
0.1.2.1
0.1.2.2
0.1.3
0.1.3.1
0.1.3.2
0.1.3.3
0.1.3.4
0.1.3.5
0.1.3.6
0.1.4
0.1.4.1
0.1.4.2
0.1.4.3

$ git branch
* master

noccylabs/plugin

Features:

How to design and interact with the plugins is up to the application host.

Concepts

Plugins have a plugin.json in a directory or archive. A Loader adds a uniform interface to deal with the plugins files and a PluginInstance is created making use of the data in the plugin.json.

Plugin.json:

{
    "name": "nullplugin",
    "version": "0.0.0",
    "implements": [
        "nothing.ever"
    ],
    "extra": {
        "description": "This plugin does nothing!"
    }
}

Generic setup:

// Specify a cache path
$pm->setCachePath(APP_ROOT."/var/cache/plugins");

// Add directories holding plugins, you can use one for internal modules
// and one for plugins.
$pm->addPluginPath(APP_ROOT."/modules");
$pm->addPluginPath(APP_ROOT."/plugins");

// Reload the plugins
$pm->reload();

Get plugins to load:

$plugin = $pm->findPlugin("my.plugin");
$plugin->load();

Or load plugin through plugin manager:

$pm->loadPlugin("my.plugin");

Or load a bunch of them:

$pm->each(function ($plugin) {
    if ($plugin->getValue("myapp.autoload")==true) {
        $plugin->load();
    }
});

Plugin Implementations

The plugin implementation is up to the implementor. In general, every plugin has a stub, which is responsible for loading the plugin. Extensions can be used to perform specific host-related tasks, such as the SymfonyExtension that adds commands and services to a symfony application.

Loaders

Working loaders:

Extensions

Working extensions:

FAQ

Q: How do I prevent the default extensions/loaders from being added?

For simplicity, the supported defaults are added. If you want to add your own, you can do so without needing to prevent the defaults. If you want to use your own set of extensions/loaders you can prevent defaults by adding some defines:

// Prevent default extensions
define("PLUGIN_NO_DEFAULT_EXTENSIONS", true);
// Prevent default loaders
define("PLUGIN_NO_DEFAULT_LOADERS", true);

Note that the defined value doesn't matter; the presence of the define is enough to prevent defaults, so if you want the defaults and have previously disabled them, make sure to comment out or remove the define entirely.