[Scummvm-cvs-logs] SF.net SVN: scummvm:[40948] web/trunk

fredrik_w at users.sourceforge.net fredrik_w at users.sourceforge.net
Wed May 27 20:24:17 CEST 2009


Revision: 40948
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40948&view=rev
Author:   fredrik_w
Date:     2009-05-27 18:24:16 +0000 (Wed, 27 May 2009)

Log Message:
-----------
Create a specific class for exception handling and modify relevant code parts. We can now properly detect if the MenuModel is causing the exception and therefor skip it.
Without this fix we wouldn't be able to display the exception if MenuModel was the cause since it's used in the Controller, which ExceptionsPage inherits from.

Modified Paths:
--------------
    web/trunk/include/Controller.php
    web/trunk/include/Pages/ExceptionsPage.php
    web/trunk/include/XMLParser.php
    web/trunk/index.php

Added Paths:
-----------
    web/trunk/include/ExceptionHandler.php

Modified: web/trunk/include/Controller.php
===================================================================
--- web/trunk/include/Controller.php	2009-05-27 17:49:20 UTC (rev 40947)
+++ web/trunk/include/Controller.php	2009-05-27 18:24:16 UTC (rev 40948)
@@ -55,8 +55,11 @@
 		$this->_content_title = '';
 		$this->_content = '';
 
+		/* The menus have caused an exception, need to skip them. */
+		if (!ExceptionHandler::skipMenus()) {
+			$menus = MenuModel::getAllMenus();
+		}
 		/* Set up the common variables before displaying. */
-		$menus = MenuModel::getAllMenus();
 		$vars = array(
 			'release' => RELEASE,
 			'release_tag' => RELEASE_TAG,

Added: web/trunk/include/ExceptionHandler.php
===================================================================
--- web/trunk/include/ExceptionHandler.php	                        (rev 0)
+++ web/trunk/include/ExceptionHandler.php	2009-05-27 18:24:16 UTC (rev 40948)
@@ -0,0 +1,36 @@
+<?php
+/** Handle uncaught exceptions. */
+abstract class ExceptionHandler {
+	static private $_exception;
+	
+	/* If the MenuModel cause the exception we need to skip them. */
+	static public function skipMenus() {
+		$skip_menus = false;
+		$e = self::$_exception;
+
+		if (!is_null($e)) {
+			if (basename($e->getFile() == 'MenuModel.php')) {
+				$skip_menus = true;
+			} else {
+				foreach ($e->getTrace() as $t) {
+					if (basename($t['file']) == 'MenuModel.php') {
+						$skip_menus = true;
+						break;
+					}
+				}
+			}
+		}
+		
+		return $skip_menus;
+	}
+	
+	/* Handle exceptions. */
+	static public function handleException(Exception $e) {
+		self::$_exception = $e;
+
+		require_once('Pages/ExceptionsPage.php');
+		$ep = new ExceptionsPage();
+		return $ep->index($e);
+	}
+}
+?>
\ No newline at end of file


Property changes on: web/trunk/include/ExceptionHandler.php
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: web/trunk/include/Pages/ExceptionsPage.php
===================================================================
--- web/trunk/include/Pages/ExceptionsPage.php	2009-05-27 17:49:20 UTC (rev 40947)
+++ web/trunk/include/Pages/ExceptionsPage.php	2009-05-27 18:24:16 UTC (rev 40948)
@@ -12,8 +12,6 @@
 
 	/* Display the index page. */
 	public function index($exception) {
-		$this->addCSSFiles(array(
-		));
 		return $this->renderPage(
 			array(
 				'title' => 'Exception',

Modified: web/trunk/include/XMLParser.php
===================================================================
--- web/trunk/include/XMLParser.php	2009-05-27 17:49:20 UTC (rev 40947)
+++ web/trunk/include/XMLParser.php	2009-05-27 18:24:16 UTC (rev 40948)
@@ -48,20 +48,21 @@
 	 * @throws ErrorException
 	 */
 	public function parseByFilename($filename) {
+		$file = "\n\nFilename: " . basename($filename) . "\n";
 		/* If we can't read the file there is nothing we can do. */
 		if (!is_file($filename) || !is_readable($filename)) {
-			throw new ErrorException(self::FILE_NOT_FOUND);
+			throw new ErrorException(self::FILE_NOT_FOUND . $file);
 		}
 		/* Read the file contents. */
 		if (!($xml = @file_get_contents($filename))) {
-			throw new ErrorException(self::FILE_NOT_READABLE);
+			throw new ErrorException(self::FILE_NOT_READABLE . $file);
 		}
 		
 		/* Parse the XML. */
 		try {
 			return $this->parseByData($xml);
 		} catch (ErrorException $e) {
-			$msg = "{$e->getMessage()}Filename: " . basename($filename) . "\n";
+			$msg = "{$e->getMessage()}{$file}";
 			throw new ErrorException($msg);
 		}
 	}
@@ -98,13 +99,13 @@
 		$replace = '<![CDATA[\\1]]>';
 		$xml = preg_replace($pattern, $replace, $xml);
 		/* Parse the data and free the parser resource. */
-		#if (!xml_parse($parser, $xml, true)) {
+		if (!xml_parse($parser, $xml, true)) {
 			$error = "\n\nError code: " . xml_get_error_code($parser) . "\n";
 			$error .= "Line: " . xml_get_current_line_number($parser) . ", character: " . xml_get_current_column_number($parser) . "\n";
 			$error .= "Error message: " . xml_error_string(xml_get_error_code($parser)) . "\n";
 			xml_parser_free($parser);
 			throw new ErrorException(self::PARSER_ERROR . $error);
-		#}
+		}
 		xml_parser_free($parser);
 		/**
 		 * The root element will contain an array with an empty key, so we can

Modified: web/trunk/index.php
===================================================================
--- web/trunk/index.php	2009-05-27 17:49:20 UTC (rev 40947)
+++ web/trunk/index.php	2009-05-27 18:24:16 UTC (rev 40948)
@@ -10,12 +10,8 @@
 }
 
 /* Exception handling. */
-function exceptionHandler (Exception $exception) {
-	require_once('Pages/ExceptionsPage.php');
-	$ep = new ExceptionsPage();
-	return $ep->index($exception);
-}
-set_exception_handler('exceptionHandler');
+require_once('ExceptionHandler.php');
+set_exception_handler(array('ExceptionHandler', 'handleException'));
 
 /* Page mapping. */
 $pages = array(


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list