From 23f478df6af0bc5b72844db33c2ea26f40ca05ce Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Mon, 8 Jan 2007 20:51:15 +0000
Subject: [PATCH] Updates to the action plugin system for better integration
with ZF 0.6.0
---
library/Nmc/Controller/Action.php | 19 ++++---------------
.../Controller/Action/Plugin/Authorize.php | 15 +++++++++++----
.../Nmc/Controller/Action/Plugin/Broker.php | 10 ++++++----
.../Controller/Action/Plugin/Interface.php | 6 ++++--
library/Nmc/Controller/Action/Plugin/Test.php | 6 ++++--
5 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/library/Nmc/Controller/Action.php b/library/Nmc/Controller/Action.php
index 62533a5..10d4f7d 100644
--- a/library/Nmc/Controller/Action.php
+++ b/library/Nmc/Controller/Action.php
@@ -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());
}
}
diff --git a/library/Nmc/Controller/Action/Plugin/Authorize.php b/library/Nmc/Controller/Action/Plugin/Authorize.php
index 308a4c3..4520e69 100644
--- a/library/Nmc/Controller/Action/Plugin/Authorize.php
+++ b/library/Nmc/Controller/Action/Plugin/Authorize.php
@@ -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
diff --git a/library/Nmc/Controller/Action/Plugin/Broker.php b/library/Nmc/Controller/Action/Plugin/Broker.php
index bbab7db..a0ea964 100644
--- a/library/Nmc/Controller/Action/Plugin/Broker.php
+++ b/library/Nmc/Controller/Action/Plugin/Broker.php
@@ -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);
}
}
diff --git a/library/Nmc/Controller/Action/Plugin/Interface.php b/library/Nmc/Controller/Action/Plugin/Interface.php
index a15b613..3f67c62 100644
--- a/library/Nmc/Controller/Action/Plugin/Interface.php
+++ b/library/Nmc/Controller/Action/Plugin/Interface.php
@@ -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);
}
diff --git a/library/Nmc/Controller/Action/Plugin/Test.php b/library/Nmc/Controller/Action/Plugin/Test.php
index 98803cb..4fdb310 100644
--- a/library/Nmc/Controller/Action/Plugin/Test.php
+++ b/library/Nmc/Controller/Action/Plugin/Test.php
@@ -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
}
--
GitLab