|
From: <pan...@us...> - 2008-09-25 11:04:49
|
Revision: 377
http://acmcontester.svn.sourceforge.net/acmcontester/?rev=377&view=rev
Author: panzaboi
Date: 2008-09-25 11:04:46 +0000 (Thu, 25 Sep 2008)
Log Message:
-----------
custom ErrorHandler to handle preDispatched NO_CONTROLLER and NO_ACTION exceptions.
Added Paths:
-----------
website/library/Ostacium/Controller/Plugin/ErrorHandler.php
Added: website/library/Ostacium/Controller/Plugin/ErrorHandler.php
===================================================================
--- website/library/Ostacium/Controller/Plugin/ErrorHandler.php (rev 0)
+++ website/library/Ostacium/Controller/Plugin/ErrorHandler.php 2008-09-25 11:04:46 UTC (rev 377)
@@ -0,0 +1,64 @@
+<?php
+
+class Ostacium_Controller_Plugin_ErrorHandler extends Zend_Controller_Plugin_ErrorHandler
+{
+ protected $_isPreDispatch = false;
+
+ public function preDispatch(Zend_Controller_Request_Abstract $request)
+ {
+ $frontController = Zend_Controller_Front::getInstance();
+ $dispatcher = $frontController->getDispatcher();
+ $response = $this->getResponse();
+
+ if ($frontController->getParam('noErrorHandler') || $this->_isInsideErrorHandlerLoop) {
+ return;
+ }
+
+ $error = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
+ $error->exception = current($response->getException());
+
+ if (!$dispatcher->isDispatchable($request)) {
+ $error->type = self::EXCEPTION_NO_CONTROLLER;
+ } elseif (!$this->isProperAction($dispatcher, $request)) {
+ $error->type = self::EXCEPTION_NO_ACTION;
+ }
+
+ if (isset($error->type)) {
+ $this->_isInsideErrorHandlerLoop = true;
+ $this->_isPreDispatch = true;
+ $this->_exceptionCountAtFirstEncounter = count($response->getException());
+
+ $error->request = clone $request;
+ $request->setParam('error_handler', $error)
+ ->setModuleName($this->getErrorHandlerModule())
+ ->setControllerName($this->getErrorHandlerController())
+ ->setActionName($this->getErrorHandlerAction());
+ }
+ }
+
+ public function postDispatch(Zend_Controller_Request_Abstract $request)
+ {
+ $response = $this->getResponse();
+ if (!$this->_isInsideErrorHandlerLoop && count($response->getException()) > $this->_exceptionCountAtFirstEncounter)
+ {
+ parent::postDispatch($request);
+ }
+
+ }
+
+ public function isProperAction($dispatcher, $request)
+ {
+ $className = $dispatcher->loadClass($dispatcher->getControllerClass($request));
+ $actionName = $request->getActionName();
+ if (empty($actionName)) {
+ $actionName = $dispatcher->getDefaultAction();
+ }
+ $methodName = $dispatcher->formatActionName($actionName);
+
+ $class = new ReflectionClass($className);
+ if ($class->hasMethod($methodName)) {
+ return true;
+ }
+ return false;
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|