I'm creating a plugin/pluggable system for my already modular content management system to make it even more flexible, and customizable when released. It's working fine so far, loads the plugins correctly when called based upon events in the 'main' code. However, I'm having trouble wrapping my head around how to return the data from several plugins.
The way my plugin system works is it will call a single method to many different plugins that have mapped an event to a function/method of theres. The problem I have is that I store each plugin return data into an array, this is fine however if a plugin returns an array, it screws the final return up ... here's the code:
Code: Select all
//---
// call_event() is the main function used to call an event to each plugin
// that has mapped it's self to an event via it's plugin map.
// @param string $event
// [@param mixed $param]
// @return mixed
//---
public function call_event( $event, $param='' ) {
if ( empty( $this->plugins ) ) {
return '';
} else {
// Find all plugins for this event and store their data
$plugins = $this->find_plugins( $event );
$plugin_data = array();
foreach( $plugins as $key=>$val ) {
$plugin_class = $this->load_plugin( $val['name'] );
if ( is_object( $plugin_class ) ) {
$method_name = $val['map'][ $event ];
if ( method_exists( $plugin_class, $method_name ) ) {
$plugin_data[] = $plugin_class->$method_name();
} else {
Log::message( 'Plugin "'.$val['name'].'" event could not be loaded. Requested event method "'.$method_name.'" does not exist in the class.', Log::L_WARNING );
}
}
}
return implode( '', $plugin_data );
}
}