From 1c5f9bb3c5d7e25666a3837300bca24f3b82d6eb Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 14 Aug 2007 01:59:04 +0000 Subject: [PATCH] Switching from calls to trigger_error() to throwing generic exceptions for client implementation errors * Installer.php * Template.php * PrinterBaseElement.php * PrinterTableElement.php * PrinterRootElementTable.php * Mail.php --- Installer.php | 2 +- Mail.php | 8 ++++---- PrinterBaseElement.php | 6 +++--- PrinterRootElementTable.php | 2 +- PrinterTableElement.php | 6 +++--- Template.php | 16 ++++++---------- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Installer.php b/Installer.php index b7a0012..5d23dab 100644 --- a/Installer.php +++ b/Installer.php @@ -180,7 +180,7 @@ abstract class BSInstaller } else { - trigger_error("step$step() does not exist in this module"); + throw new Exception("step$step() does not exist in this module"); } } diff --git a/Mail.php b/Mail.php index a04bcd5..046ac69 100644 --- a/Mail.php +++ b/Mail.php @@ -183,7 +183,7 @@ class BSMail { if (empty($address)) { - trigger_error('You need to specify an email address'); + throw new Exception('You need to specify an email address'); } // load the input sanitizer @@ -214,7 +214,7 @@ class BSMail $from = trim($input->unsanitize($from)); if (empty($from)) { - trigger_error('You need to specify a from email address'); + throw new Exception('You need to specify a from email address'); } // sanitize the from name @@ -227,7 +227,7 @@ class BSMail $subject = trim($unsanitize($subject)); if (empty($subject)) { - trigger_error('You need to specify a subject for the message'); + throw new Exception('You need to specify a subject for the message'); } // sanitize the body @@ -235,7 +235,7 @@ class BSMail $bodyText = trim($input->unsanitize($bodyText, true)); if (empty($bodyText)) { - trigger_error('You need to specify body text before sending the message'); + throw new Exception('You need to specify body text before sending the message'); } // attach additional headers diff --git a/PrinterBaseElement.php b/PrinterBaseElement.php index 79359a0..0ed1a83 100644 --- a/PrinterBaseElement.php +++ b/PrinterBaseElement.php @@ -105,7 +105,7 @@ class BSPrinterBaseElement extends BSPrinterElement { if (!in_array($this->type, array('checkbox', 'radio', 'option'))) { - trigger_error('BSPrinterBaseElement::setActive() can only be used on elements of type checkbox, radio, or option'); + throw new Exception('BSPrinterBaseElement::setActive() can only be used on elements of type checkbox, radio, or option'); } $this->active = $active; } @@ -214,14 +214,14 @@ class BSPrinterBaseElement extends BSPrinterElement case 'textarea': if (!isset($this->style['height']) OR !isset($this->style['width'])) { - trigger_error('BSPrinterBaseElement of type "textarea" require a "height" and "width" style attribute'); + throw new Exception('BSPrinterBaseElement of type "textarea" require a "height" and "width" style attribute'); } return '_prepareStyle() . $accesskey . '>' . $this->value . ''; break; default: - trigger_error('Invalid PrinterBaseElement type "' . $this->type . '"'); + throw new Exception('Invalid PrinterBaseElement type "' . $this->type . '"'); break; } } diff --git a/PrinterRootElementTable.php b/PrinterRootElementTable.php index 2cc560c..763fd17 100644 --- a/PrinterRootElementTable.php +++ b/PrinterRootElementTable.php @@ -78,7 +78,7 @@ class BSPrinterRootElementTable extends BSPrinterRootElement { if (!$tr instanceof BSPrinterTableElement) { - trigger_error('BSPrinterRootElementTable::addChild() only accepts BSPrinterTableElement objects as children'); + throw new Exception('BSPrinterRootElementTable::addChild() only accepts BSPrinterTableElement objects as children'); } $this->children[] = $tr; } diff --git a/PrinterTableElement.php b/PrinterTableElement.php index d1c5e0c..d81d722 100644 --- a/PrinterTableElement.php +++ b/PrinterTableElement.php @@ -175,7 +175,7 @@ class BSPrinterTableElement extends BSPrinterElement } else { - trigger_error('Only BSPrinterBaseElement\'s of type "option" are allowed in BSPrinterTableElement::RowList()'); + throw new Exception('Only BSPrinterBaseElement\'s of type "option" are allowed in BSPrinterTableElement::RowList()'); } } @@ -212,7 +212,7 @@ class BSPrinterTableElement extends BSPrinterElement } else { - trigger_error('Only BSPrinterBaseElement\'s of type "checkbox" are allowed in BSPrinterTableElement::RowCheckbox()'); + throw new Exception('Only BSPrinterBaseElement\'s of type "checkbox" are allowed in BSPrinterTableElement::RowCheckbox()'); } } @@ -325,7 +325,7 @@ class BSPrinterTableElement extends BSPrinterElement { if ($cols < $this->numberOfColumns()) { - trigger_error('You need to have at least ' . $this->numberOfColumns() . ' columns'); + throw new Exception('You need to have at least ' . $this->numberOfColumns() . ' columns'); } $this->colspan = $cols; } diff --git a/Template.php b/Template.php index 8dda1d1..0395f6c 100644 --- a/Template.php +++ b/Template.php @@ -162,7 +162,7 @@ class BSTemplate { if (sizeof($this->cache) > 0) { - trigger_error('You cannot cache templates more than once per initialization'); + throw new Exception('You cannot cache templates more than once per initialization'); } else { @@ -254,14 +254,12 @@ class BSTemplate if (empty($template)) { - trigger_error('There was no output to print'); - exit; + throw new Exception('There was no output to print'); } if ($this->doneflush) { - trigger_error('A template has already been sent to the output buffer'); - exit; + throw new Exception('A template has already been sent to the output buffer'); } $debugBlock = ''; @@ -343,14 +341,12 @@ class BSTemplate } else { - trigger_error("Could not load the template '$path'"); - exit; + throw new Exception("Could not load the template '$path'"); } } else { - trigger_error("Could not load the template '$path'"); - exit; + throw new Exception("Could not load the template '$path'"); } } @@ -521,7 +517,7 @@ class BSTemplate } else { - trigger_error('Invalid language variable index "' . $capture . '"'); + throw new Exception('Invalid language variable index "' . $capture . '"'); } } else if ($template[$i] == '>' AND $template[$i - 1] == '"') -- 2.22.5