I'm currently writing a little PHP application for myself for which I'd like to add a simple plugin extensibility.
I did found some ideas on how to do this, but I had the feeling they all were way too complex for my needs.
Let me explain what exactly I need:
My application is supposed to do one simple task, for example: perform a web search.
The user should be able to choose, which plugin is getting used.
For example, you could have a Google, Yahoo, and Bing plugin to choose from.
Each plugin would have a function "performWebSearch" which returns the search results.
Yeah, that's basically it.
I can show you what code I currently use, to make it more clear:
To get a list of existing plugins:
$classes_before = get_declared_classes();
foreach(glob("../plugins/*.plugin.php") as $filename) include $filename;
$classes_after = get_declared_classes();
foreach($classes_after as $class)
{
if(!in_array($class, $classes_before))
{
$plugins_available[] = $class;
}
}
And this is how a "plugin" currently looks like:
class google
{
public $name = "Google Search";
public $version = 1.0;
public function performWebSearch($query)
{
// ...
}
}
This works, but it feels "dirty" doing it that way.
I'm sure there is a way better method to do this but I have no idea what it could be.
I appreciate any help.
Thanks.