MINOR: updated set_spam_protector to throw a warning if an incorrect spam protector is detected. MINOR: added exception output to warning to make debugging easier

This commit is contained in:
Will Rossiter 2009-08-11 02:51:03 +00:00
parent de8e50ad5c
commit c2315c1618

View File

@ -1,15 +1,19 @@
<?php <?php
/** /**
* This class is responsible for setting an system-wide spam protecter field * This class is responsible for setting an system-wide spam protecter field
* and add the protecter field to a form * and add the protecter field to a form.
*
* @package spamprotection
*/ */
class SpamProtectorManager { class SpamProtectorManager {
static $spam_protector = null; static $spam_protector = null;
/** /**
* Set the name of the spam protecter class * Set the name of the spam protecter class
* @param string the name of protecter field class *
* @param String the name of protecter field class
*/ */
static function set_spam_protector($protector) { static function set_spam_protector($protector) {
self::$spam_protector = $protector; self::$spam_protector = $protector;
@ -37,13 +41,16 @@ class SpamProtectorManager {
static function update_form($form, $before=null, $fieldsToSpamServiceMapping=null) { static function update_form($form, $before=null, $fieldsToSpamServiceMapping=null) {
$check = null; $check = null;
$protectorClass = self::$spam_protector; $protectorClass = self::$spam_protector;
if(!class_exists($protectorClass)) return null;
if(!class_exists($protectorClass)) {
user_error("Spam Protector class '$protectorClass' does not exist. Please define a valid Spam Protector", E_USER_WARNING);
}
$protector = new $protectorClass(); $protector = new $protectorClass();
try { try {
$check = $protector->updateForm($form, $before, $fieldsToSpamServiceMapping); $check = $protector->updateForm($form, $before, $fieldsToSpamServiceMapping);
} catch (Exception $e) { } catch (Exception $e) {
user_error("SpamProtectorManager::update_form(): '$protectorClass' is not correctly set up.", E_USER_WARNING); user_error("SpamProtectorManager::update_form(): '$protectorClass' is not correctly set up. " . $e, E_USER_WARNING);
} }
if(!$check) return null; if(!$check) return null;