Plugins
Plugins are the primary way to alter or intercept requests and responses in Alloy. Plugins are also the primary way to add new functionaliy to Alloy by extending the Kernel with your own dynamic methods, add filters, and observe triggered events.
Creating Plugins
Plugins can either be standalone plugins placed in the app/Plugin directory, or a Module plugin inside the app/Module directory. The most basic plugin consists of a single file named Plugin.php inside a named directory that the plugin will be referenced by, like 'Oauth'. Plugins, like Modules, are designed to be fully self-contained within a single folder for maximum portability between projects and for easier disribution and packaging. Also like Modules, Plugins can be as complex as you want them to be, and can contain and activate other plugins, libraries, and class files as sub-packages, as many levels deep as you need.
This example plugin code below adds the Symfony2 Finder Component to your Alloy project.
File: app/Plugin/Finder/Plugin.php
The Finder plugin has a folder hierarchy that looks like this:
- alloy/
- app/
- Plugin/
- Finder/
- Plugin.php
- lib/
- Symfony/
- Component/
- Finder/
- Finder.php
- Glob.php
- ... etc ...
- Finder/
- Component/
- Symfony/
- Finder/
- Plugin/
Enabling and Disabling Plugins
Plugins must be explicitly enabled by adding them to the plugins configuration setting.