Using plugins - linusnorton/xFrame GitHub Wiki
Plugins in xFrame allow you to easily inject an object into the Dependency Injection Container. This allows you to gain access to your object so long as you can access the DIC.
Setup
Edit your config file (dev.ini
, test.ini
or live.ini
) and add the following line under [plugin]
PLUGIN[MyPlugin]=\my\Plugin
Next you need to create your plugin class which needs to extend \xframe\plugin\Plugin
and implement the init
method.
namespace my;
class Plugin extends \xframe\plugin\Plugin {
public function init() {
// plugin init code here
}
}
Usage
You can then access an instance of your plugin in your code like this (assuming $dic
is an instance of \xframe\util\Container\DependencyInjectionContainer
.
$myPlugin = $dic->plugin['MyPlugin'];