A dispatch table is the first idea that springs to mind for me:
class Controller
{
private $plugins = [];
public function addPlugin($foo)
{
$this->plugins[] = $foo;
}
public function removePlugin($foo)
{
$key = array_search($foo, $this->plugins, true);
if($key !== false)
{
unset($this->plugins[$key]);
}
}
public function __call($func, $args)
{
foreach($this->plugins as $plugin)
{
if(method_exists($plugin, $func))
{
return call_user_func_array([$plugin, $func], $args);
}
}
}
}
class Britches
{
public function getFunky()
{
return "FUNKY!";
}
}
$t = new Controller;
$t->addPlugin(new Britches);
echo $t->getFunky();
Obviously there'd be more to it than that in a real implementation (there are things like having the plugin publish its interface (say as a set of Command objects), conflict resolution, and so on), but it's just there to illustrate the idea in under fifty lines.