Skip to content
Snippets Groups Projects
Commit 23f478df authored by Tim Steiner's avatar Tim Steiner
Browse files

Updates to the action plugin system for better integration with ZF 0.6.0

parent 615e3522
No related branches found
No related tags found
No related merge requests found
......@@ -32,17 +32,6 @@ abstract class Nmc_Controller_Action extends Zend_Controller_Action {
*/
protected $_pluginBroker;
public function run(Zend_Controller_Dispatcher_Interface $dispatcher,
Zend_Controller_Dispatcher_Token $action)
{
$this->_action = $action;
$this->_params = $action->getParams();
$this->_preAction();
$returnValue = parent::run($dispatcher, $action);
$this->_postAction();
return $returnValue;
}
protected function _registerPlugin(Nmc_Controller_Action_Plugin_Interface $plugin)
{
if(! $this->_pluginBroker instanceof Nmc_Controller_Action_Plugin_Broker) {
......@@ -58,17 +47,17 @@ abstract class Nmc_Controller_Action extends Zend_Controller_Action {
}
}
protected function _preAction()
public function preDispatch()
{
if($this->_pluginBroker instanceof Nmc_Controller_Action_Plugin_Broker) {
$this->_pluginBroker->preAction($this, $this->_action);
$this->_pluginBroker->preAction($this, $this->getRequest(), $this->getResponse());
}
}
protected function _postAction()
public function postDispatch()
{
if($this->_pluginBroker instanceof Nmc_Controller_Action_Plugin_Broker) {
$this->_pluginBroker->postAction($this, $this->_action);
$this->_pluginBroker->postAction($this, $this->getRequest(), $this->getResponse());
}
}
......
......@@ -13,16 +13,23 @@ class Nmc_Controller_Action_Plugin_Authorize implements Nmc_Controller_Action_Pl
{
public function preAction(Nmc_Controller_Action $controller,
Zend_Controller_Dispatcher_Token $action)
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response)
{
if($request->getActionName() == 'unauthorized') {
return;
}
$authorized = false;
if(!$controller->authorize()) {
$action->setActionName('unauthorized');
$request->setActionName('unauthorized');
$request->setDispatched(false);
}
}
public function postAction(Nmc_Controller_Action $controller,
Zend_Controller_Dispatcher_Token $action)
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response)
{
//do nothing
}
......@@ -38,7 +45,7 @@ class Nmc_Controller_Action_Plugin_Authorize implements Nmc_Controller_Action_Pl
$out = new Nmc_View();
$out->page = '403';
$out->title = '403 Access Denied';
echo $out->render();
echo $out->render('index.xhtml');
}
}
\ No newline at end of file
......@@ -48,18 +48,20 @@ class Nmc_Controller_Action_Plugin_Broker implements Nmc_Controller_Action_Plugi
}
public function preAction(Nmc_Controller_Action $controller,
Zend_Controller_Dispatcher_Token $action)
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response)
{
foreach($this->_plugins as $plugin) {
$plugin->preAction($controller, $action);
$plugin->preAction($controller, $request, $response);
}
}
public function postAction(Nmc_Controller_Action $controller,
Zend_Controller_Dispatcher_Token $action)
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response)
{
foreach($this->_plugins as $plugin) {
$plugin->postAction($controller, $action);
$plugin->postAction($controller, $request, $response);
}
}
......
......@@ -24,10 +24,12 @@
interface Nmc_Controller_Action_Plugin_Interface {
public function preAction(Nmc_Controller_Action $controller,
Zend_Controller_Dispatcher_Token $action);
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response);
public function postAction(Nmc_Controller_Action $controller,
Zend_Controller_Dispatcher_Token $action);
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response);
}
......
......@@ -13,14 +13,16 @@ class Nmc_Controller_Action_Plugin_Test implements Nmc_Controller_Action_Plugin_
{
public function preAction(Nmc_Controller_Action $controller,
Zend_Controller_Dispatcher_Token $action)
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response)
{
$foo = new ReflectionObject($controller);
//print_r($foo->__toString());
}
public function postAction(Nmc_Controller_Action $controller,
Zend_Controller_Dispatcher_Token $action)
Zend_Controller_Request_Abstract $request,
Zend_Controller_Response_Abstract $response)
{
//do nothing
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment