Select Git revision
Forked from
UNL Information Services / NMC-PHP-Framework
105 commits behind the upstream repository.
Broker.php 2.36 KiB
<?php
/**
* Nmc_Controller_Action_Plugin_Broker: class to deal with calling plugin methods
*
* LICENSE: Some license information
*
* @copyright 2006 New Media Center - University of Nebraska-Lincoln
* @license http://www.gnu.org/licenses/gpl.txt GPL
* @version 0.0.1
* @link http://nmc.unl.edu/
* @since File available since Release 0.0.1
*/
require_once 'Nmc/Controller/Action/Plugin/Interface.php';
/**
* * Nmc_Controller_Action_Plugin_Broker
*
* @copyright 2006 New Media Center - University of Nebraska Lincoln
* @license http://www.gnu.org/gpl.txt GPL
* @version Release: 0.0.1
* @link http://nmc.unl.edu/
* @since Class available since Release 0.0.1
*/
class Nmc_Controller_Action_Plugin_Broker implements Nmc_Controller_Action_Plugin_Interface
{
protected $_plugins;
public function __construct()
{
$this->_plugins = array();
}
public function registerPlugin(Nmc_Controller_Action_Plugin_Interface $plugin)
{
if(!in_array($plugin, $this->_plugins, true)) {
$this->_plugins[] = $plugin;
}
}
public function unregisterPlugin(Nmc_Controller_Action_Plugin_Interface $plugin)
{
$key = array_search($plugin, $this->_plugins, true);
if($key !== false) {
unset($this->_plugins[$key]);
}
}
public function preAction(Nmc_Controller_Action $controller,
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response)
{
foreach($this->_plugins as $plugin) {
$plugin->preAction($controller, $request, $response);
}
}
public function postAction(Nmc_Controller_Action $controller,
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response)
{
foreach($this->_plugins as $plugin) {
$plugin->postAction($controller, $request, $response);
}
}
public function pluginMethodExists($method)
{
foreach($this->_plugins as $plugin) {
if(method_exists($plugin, $method)) {
return true;
}
}
return false;
}
public function callPluginMethod($method, $args)
{
foreach($this->_plugins as $plugin) {
if(method_exists($plugin, $method)) {
return call_user_func_array(array($plugin, $method), $args);
}
}
}
}
?>