From 4bedd361ec6aa3791eb196213192b26e287b67a3 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Wed, 5 Jan 2011 08:26:41 +0000
Subject: [PATCH] Add option to use a custom error handling function.

Thanks to Andjelko Horvat for implementing this feature!

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2699 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Error/Error.php | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/lib/SimpleSAML/Error/Error.php b/lib/SimpleSAML/Error/Error.php
index 781560728..796681c42 100644
--- a/lib/SimpleSAML/Error/Error.php
+++ b/lib/SimpleSAML/Error/Error.php
@@ -145,29 +145,38 @@ class SimpleSAML_Error_Error extends SimpleSAML_Error_Exception {
 		$errorData = $this->saveError();
 
 		$config = SimpleSAML_Configuration::getInstance();
-		$t = new SimpleSAML_XHTML_Template($config, 'error.php', 'errors');
-		$t->data['showerrors'] = $config->getBoolean('showerrors', true);
-		$t->data['error'] = $errorData;
-		$t->data['errorCode'] = $this->errorCode;
-		$t->data['parameters'] = $this->parameters;
+
+		$data['showerrors'] = $config->getBoolean('showerrors', true);
+		$data['error'] = $errorData;
+		$data['errorCode'] = $this->errorCode;
+		$data['parameters'] = $this->parameters;
 
 		/* Check if there is a valid technical contact email address. */
 		if($config->getString('technicalcontact_email', 'na@example.org') !== 'na@example.org') {
 			/* Enable error reporting. */
 			$baseurl = SimpleSAML_Utilities::getBaseURL();
-			$t->data['errorReportAddress'] = $baseurl . 'errorreport.php';
+			$data['errorReportAddress'] = $baseurl . 'errorreport.php';
 		}
 
 		$session = SimpleSAML_Session::getInstance();
 		$attributes = $session->getAttributes();
 		if (is_array($attributes) && array_key_exists('mail', $attributes) && count($attributes['mail']) > 0) {
-			$email = $attributes['mail'][0];
+			$data['email'] = $attributes['mail'][0];
+		} else {
+			$data['email'] = '';
+		}
+
+		$show_function = $config->getString('errors.show_function', NULL);
+		if (isset($show_function)) {
+			assert('is_callable($show_function)');
+			call_user_func($show_function, $config, $data);
+			assert('FALSE');
 		} else {
-			$email = '';
+			$t = new SimpleSAML_XHTML_Template($config, 'error.php', 'errors');
+			$t->data = array_merge($t->data, $data);
+			$t->show();
 		}
-		$t->data['email'] = $email;
 
-		$t->show();
 		exit;
 	}
 
-- 
GitLab