Update version.php to 3.3.0
[isso.git] / Api.php
diff --git a/Api.php b/Api.php
index 1c0274112d7fa2a0b05e5d4fa633fb37953b99ef..aa6d6ca79b91b5482c13fc60485e44e66b611da6 100644 (file)
--- a/Api.php
+++ b/Api.php
@@ -1,12 +1,12 @@
 <?php
 /*=====================================================================*\
 || ###################################################################
-|| # Blue Static ISSO Framework [#]issoversion[#]
-|| # Copyright ©2002-[#]year[#] Blue Static
+|| # Blue Static ISSO Framework
+|| # Copyright (c)2005-2009 Blue Static
 || #
 || # This program is free software; you can redistribute it and/or modify
 || # it under the terms of the GNU General Public License as published by
-|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| # the Free Software Foundation; version 2 of the License.
 || #
 || # This program is distributed in the hope that it will be useful, but
 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 \*=====================================================================*/
 
 /**
-* Abstract Datamanger API (api.php)
-*
-* @package     ISSO
-*/
+ * Abstract Datamanger API (api.php)
+ *
+ * @package    ISSO
+ */
 
 if (!defined('REQ_AUTO'))
 {      
        /**
-       * Yes, required
-       */
+        * Yes, required
+        */
        define('REQ_YES', 1);
        
        /**
-       * No, not required
-       */
+        * No, not required
+        */
        define('REQ_NO', 0);
 
        /**
-       * Auto-increasing value
-       */
+        * Auto-increasing value
+        */
        define('REQ_AUTO', -1);
        
        /**
-       * Set by a cusotm set_*() function
-       */
+        * Set by a cusotm set_*() function
+        */
        define('REQ_SET', 2);
        
        /**
-       * Index for cleaning type
-       */
+        * Index for cleaning type
+        */
        define('F_TYPE', 0);
        
        /**
-       * Index for requirement type
-       */
+        * Index for requirement type
+        */
        define('F_REQ', 1);
-       
-       /**
-       * Index for verification type
-       */
-       define('F_VERIFY', 2);
 }
 
 /**
-* Abstract API
-*
-* Abstract class that is used as an API base for most common database interaction
-* schemes. Creates a simple structure that holds data and can update, remove, and
-* insert.
-*
-* @author              Blue Static
-* @copyright   Copyright ©2002 - [#]year[#], Blue Static
-* @version             $Revision$
-* @package             ISSO
-* 
-*/
+ * Abstract API
+ *
+ * Abstract class that is used as an API base for most common database interaction
+ * schemes. Creates a simple structure that holds data and can update, delete, and
+ * insert.
+ * 
+ * Life-cycle of a new object:
+ * 1. $o = new SubApi();
+ * 2. $o->set('foo', 'abc');
+ * 3. $o->set('test', 45);
+ * 4. try { $o->insert(); <other actions that depend on the saved record> } catch (ApiException $e) {}
+ *
+ * @author             Blue Static
+ * @copyright  Copyright (c)2005 - 2009, Blue Static
+ * @package            ISSO
+ * 
+ */
 abstract class BSApi
 {
        /**
-       * Fields: used for verification and sanitization
-       * NAME => array(TYPE, REQUIRED, VERIFY METHOD (:self for self-named method), RELATION => array(FILE, CLASS IN FILE, ALTERNATE FIELD NAME))
-       * @var  array
-       */
+        * Fields: used for verification and sanitization
+        * NAME => array(TYPE, REQUIRED)
+        * @var array
+        */
        protected $fields = array();
        
        /**
-       * Values array: sanitized and verified field values
-       * @var  array
-       */
+        * The table name the API maps objects for
+        * @var string
+        */
+       protected $table = '___UNDEFINED___';
+       
+       /**
+        * The database table prefix
+        * @var string
+        */
+       protected $prefix = '';
+       
+       /**
+        * Values array: sanitized and validated field values
+        * @var array
+        */
        public $values = array();
        
        /**
-       * Fields that were manually set with set(), not by using setExisting()
-       * @var  array
-       */
+        * Fields that were set by the client
+        * @var array
+        */
        private $setfields = array();
        
        /**
-       * WHERE condition
-       * @var  string
-       */
-       private $condition = '';
+        * WHERE condition
+        * @var string
+        */
+       protected $condition = '';
        
        /**
-       * The object table row; a fetched row that represents this instance
-       * @var  array
-       */
-       public $objdata = array();
+        * The object table row; a fetched row that represents this instance
+        * @var array
+        */
+       public $record = array();
        
        /**
-       * Insert ID from the insert() command
-       * @var  integer
-       */
+        * Insert ID from the insert() command
+        * @var integer
+        */
        public $insertid = 0;
        
        /**
-       * Error list that has been generated
-       * @var  array
-       */
-       private $errors = array();
+        * Error queue that builds up errors
+        * @var ApiException
+        */
+       private $exception = null;
        
-       // ###################################################################
        /**
-       * Constructor: cannot instantiate class directly
-       */
+        * Constructor
+        */
        public function __construct()
        {
-               BSRegister::RequiredModules(array('Db', 'Input'));
+               if (!BSApp::$input instanceof BSInput)
+               {
+                       throw new Exception('BSApp::$input is not an instance of BSInput');
+               }
+               if (!BSApp::$db instanceof BSDb)
+               {
+                       throw new Exception('BSApp::$db is not an instance of BSDb');
+               }
        }
        
-       // ###################################################################
        /**
-       * Constructs an error for the error handler to receive
-       *
-       * @param        string  Error message
-       */
-       protected function _error($message)
+        * Adds an error into the error queue that is then hit 
+        *
+        * @param       Exception       Error message
+        */
+       protected function _error(Exception $e)
        {
-               $this->errors[] = $message;
-               
-               // we want to explicitly specify silence
-               if (APIError() == 'silent')
+               if ($this->exception == null)
                {
-                       return;
+                       $this->exception = new ApiException();
                }
-               
-               if (!is_callable(APIError()))
+               $this->exception->addException($e);
+       }
+       
+       /**
+        * This simply throws the ApiException if it exists, which inside holds
+        * all of the individual and specific errors
+        */
+       protected function _processErrorQueue()
+       {
+               if ($this->exception)
                {
-                       trigger_error('No APIError() handler has been set');
+                       throw $this->exception;
+               }
+       }
+       
+       /**
+        * Sets an array of data into the API, ignoring things in $exclude. Keys
+        * in the array that don't exist in the API will be ignored.
+        * 
+        * @param       array   A dictionary of field names and values to set
+        * @param       array   Array of keys to exclude
+        */
+       public function setArray(Array $data, $exclude = array())
+       {
+               foreach ($data as $key => $value)
+               {
+                       if (in_array($key, $exclude) || !isset($this->fields[$key]))
+                       {
+                               continue;
+                       }
+                       $this->set($key, $value);
                }
-               
-               call_user_func(APIError(), $message);
        }
        
-       // ###################################################################
        /**
-       * Returns the error list. This is because we don't want people mucking
-       * with the error system. It will return an empty array if there are
-       * no errors.
-       *
-       * @return       array   Array of errors
-       */
-       public function checkErrors()
+        * Resets the API object to an initial state. This will NOT clear the primary (REQ_AUTO)
+        * field.
+        */
+       public function reset()
        {
-               if (sizeof($this->errors) < 1)
+               foreach ($this->fields as $field => $settings)
                {
-                       return array();
+                       if ($settings[F_REQ] == REQ_AUTO)
+                       {
+                               $savename       = $field;
+                               $savevalue      = $this->fetchValue($field);
+                               $savevalue      = ($savevalue ? $savevalue : $this->insertid);
+                               break;
+                       }
                }
                
-               return $this->errors;
+               $this->setfields        = array();
+               $this->values           = array();
+               $this->condition        = '';
+               $this->insertid         = 0;
+               $this->exception        = null;
+               
+               $this->set($savename, $savevalue);
        }
        
-       // ###################################################################
        /**
-       * Sets a value, sanitizes it, and verifies it
-       *
-       * @param        string  Field name
-       * @param        mixed   Value
-       * @param        bool    Do clean?
-       * @param        bool    Do verify?
-       */
-       public function set($field, $value, $doclean = true, $doverify = true)
+        * Sets a value, sanitizes it, and validates it
+        *
+        * @param       string  Field name
+        * @param       mixed   Value
+        * @param       bool    Do clean?
+        * @param       bool    Do validation?
+        */
+       public function set($field, $value, $doclean = true, $dovalidate = true)
        {
                if (!isset($this->fields["$field"]))
                {
-                       trigger_error('Field "' . $field . '" is not valid');
-                       return;
+                       throw new Exception('Field "' . $field . '" is not valid');
                }
                
-               $this->values["$field"] = ($doclean ? BSRegister::GetType('Input')->clean($value, $this->fields["$field"][F_TYPE]) : $value);
+               $this->values["$field"] = ($doclean ? BSApp::$input->clean($value, $this->fields["$field"][F_TYPE]) : $value);
                
                $this->setfields["$field"] = $field;
                
-               if (isset($this->fields["$field"][F_VERIFY]) AND $doverify)
+               if ($dovalidate && method_exists($this, "validate_$field"))
                {
-                       if ($this->fields["$field"][F_VERIFY] == ':self')
-                       {
-                               $verify = $this->{"verify_$field"}($field);
-                       }
-                       else
-                       {
-                               $verify = $this->{$this->fields["$field"][F_VERIFY]}($field);
-                       }
-                       
-                       if ($verify !== true)
-                       {
-                               if ($verify === false)
-                               {
-                                       $this->error(sprintf(_('Validation of "%1$s" failed'), $field));
-                               }
-                               else
-                               {
-                                       $this->error($verify);
-                               }
-                       }
+                       $this->{"validate_$field"}($field);
                }
        }
        
-       // ###################################################################
        /**
-       * Sets the condition to use in the WHERE clause; if not passed, then
-       * it calculates it from the REQ_AUTO field
-       *
-       * @param        mixed   String with WHERE condition; array of fields to use for WHERE builder
-       */
-       public function setCondition($condition = '')
+        * Sets the condition to use in the WHERE clause; if not passed, then
+        * it calculates it from the REQ_AUTO field
+        *
+        * @param       mixed   String with WHERE condition; array of fields to use for WHERE builder
+        */
+       public function setCondition($condition = null)
        {
-               if (is_array($condition) AND sizeof($condition) > 0)
+               if (is_array($condition) && sizeof($condition) > 0)
                {
                        $this->condition = '';
                        
-                       foreach ($condition AS $field)
+                       foreach ($condition as $field)
                        {
                                if (!$this->values["$field"])
                                {
-                                       trigger_error('The specified field "' . $field . '" for the condition could not be found as it is not set');
-                                       continue;
+                                       throw new Exception('The specified field "' . $field . '" for the condition could not be found as it is not set');
                                }
                                
                                $condbits[] = "$field = " . $this->_prepareFieldForSql($field);
                        }
                        $this->condition = implode(' AND ', $condbits);
                }
-               else if ($condition != '')
+               else if ($condition)
                {
                        $this->condition = $condition;
                }
                else 
                {
-                       foreach ($this->fields AS $name => $options)
+                       foreach ($this->fields as $name => $options)
                        {
                                if ($options[F_REQ] == REQ_AUTO)
                                {
                                        if (!$this->values["$name"])
                                        {
-                                               trigger_error('Cannot determine condition from the REQ_AUTO field because it is not set');
-                                               continue;
+                                               throw new Exception('Cannot determine condition from the REQ_AUTO field because it is not set');
                                        }
                                        
                                        $this->condition = "$name = " . $this->_prepareFieldForSql($name);
                                }
                        }
                        
-                       if ($this->condition == '')
-                       {
-                               trigger_error('No REQ_AUTO fields are present and therefore the condition cannot be created');
-                       }
-               }
-       }
-       
-       // ###################################################################
-       /**
-       * Sets existing data into $values where it's not already present
-       */
-       public function setExisting()
-       {
-               static $run;
-               if ($run)
-               {
-                       return;
-               }
-               
-               $this->fetch();
-               
-               foreach ($this->objdata AS $field => $value)
-               {
-                       if (!isset($this->values["$field"]))
+                       if (!$this->condition)
                        {
-                               $this->values["$field"] = $value;
+                               throw new Exception('No REQ_AUTO fields are present and therefore the condition cannot be created');
                        }
                }
-               
-               $run = true;
        }
        
-       // ###################################################################
        /**
-       * Fetches a record based on the condition
-       *
-       * @param        bool    Run pre_fetch()?
-       * @param        bool    Run post_fetch()?
-       */
+        * Fetches a record based on the condition
+        *
+        * @param       bool    Run pre_fetch()?
+        * @param       bool    Run post_fetch()?
+        *
+        * @return      boolean Whether or not the row was successfully fetched
+        */
        public function fetch($doPre = true, $doPost = true)
        {
-               if ($this->condition == '')
+               if (!$this->condition)
                {
                        $this->setCondition();
                }
                
+               // reset the error queue due to any validation errors caused by fetchable fields
+               $this->errors = null;
+               
                $this->_runActionMethod('pre_fetch', $doPre);
                
-               $result = BSRegister::GetType('Db')->queryFirst("SELECT * FROM {$this->prefix}{$this->table} WHERE {$this->condition}");
+               $result = BSApp::$db->queryFirst("SELECT * FROM {$this->prefix}{$this->table} WHERE {$this->condition}");
                if (!$result)
                {
-                       $this->error(_('No records were returned'));
-                       return;
+                       return false;
                }
                
                $this->_runActionMethod('post_fetch', $doPost);
                
-               $this->objdata = $result;
+               $this->record = $result;
                
-               if ($populate)
-               {
-                       foreach ($this->objdata AS $key => $value)
-                       {
-                               if (!isset($this->values["$key"]))
-                               {
-                                       $this->values["$key"] = $value;
-                               }
-                       }
-               }
+               return true;
        }
        
-       // ###################################################################
        /**
-       * Inserts a record in the database
-       *
-       * @param        bool    Run pre_insert()?
-       * @param        bool    Run post_insert()?
-       */
+        * Inserts a record in the database
+        *
+        * @param       bool    Run pre_insert()?
+        * @param       bool    Run post_insert()?
+        */
        public function insert($doPre = true, $doPost = true)
        {
-               $this->verify();
+               $this->_verifyRequired();
+               $this->_processErrorQueue();
                
                $this->_runActionMethod('pre_insert', $doPre);
                
-               foreach ($this->setfields AS $field)
+               $fields = $values = array();
+               foreach ($this->setfields as $field)
                {
                        $fields[] = $field;
                        $values[] = $this->_prepareFieldForSql($field);
                }
                
-               BSRegister::GetType('Db')->query("INSERT INTO {$this->prefix}{$this->table} (" . implode(',', $fields) . ") VALUES (" . implode(',', $values) . ")");
+               BSApp::$db->query("INSERT INTO {$this->prefix}{$this->table} (" . implode(',', $fields) . ") VALUES (" . implode(',', $values) . ")");
                
-               if (BSRegister::GetType('DbPostgreSql'))
+               if (BSApp::$db instanceof BSDbPostgreSql)
                {
-                       foreach ($this->fields AS $field => $info)
+                       foreach ($this->fields as $field => $info)
                        {
                                if ($info[F_REQ] == REQ_AUTO)
                                {
@@ -366,79 +359,78 @@ abstract class BSApi
                                }
                        }
                        
-                       $this->insertid = BSRegister::GetType('Db')->insertId($this->prefix . $this->table, $autofield);
+                       $this->insertid = BSApp::$db->insertId($this->prefix . $this->table, $autofield);
                }
                else
                {
-                       $this->insertid = BSRegister::GetType('Db')->insertId();
+                       $this->insertid = BSApp::$db->insertId();
                }
                
                $this->_runActionMethod('post_insert', $doPost);
        }
        
-       // ###################################################################
        /**
-       * Updates a record in the database using the data in $vaues
-       *
-       * @param        bool    Run pre_update()?
-       * @param        bool    Run post_update()?
-       */
+        * Updates a record in the database using the data in $vaues
+        *
+        * @param       bool    Run pre_update()?
+        * @param       bool    Run post_update()?
+        */
        public function update($doPre = true, $doPost = true)
        {
-               if ($this->condition == '')
+               if (!$this->condition)
                {
                        $this->setCondition();
                }
-
+               
+               $this->_processErrorQueue();
+               
                $this->_runActionMethod('pre_update', $doPre);
                
-               foreach ($this->setfields AS $field)
+               foreach ($this->setfields as $field)
                {
                        $updates[] = "$field = " . $this->_prepareFieldForSql($field);
                }
                $updates = implode(', ', $updates);
                
-               BSRegister::GetType('Db')->query("UPDATE {$this->prefix}{$this->table} SET $updates WHERE {$this->condition}");
+               BSApp::$db->query("UPDATE {$this->prefix}{$this->table} SET $updates WHERE {$this->condition}");
                
                $this->_runActionMethod('post_update', $doPost);
        }
        
-       // ###################################################################
        /**
-       * Deletes a record
-       *
-       * @param        bool    Run pre_remove()?
-       * @param        bool    Run post_remove()?
-       */
-       public function remove($doPre = true, $doPost = true)
+        * Deletes a record
+        *
+        * @param       bool    Run pre_delete()?
+        * @param       bool    Run post_delete()?
+        */
+       public function delete($doPre = true, $doPost = true)
        {
-               if ($this->condition == '')
+               if (!$this->condition)
                {
                        $this->setCondition();
                }
                
                $this->fetch();
                
-               $this->_runActionMethod('pre_remove', $doPre);
+               $this->_runActionMethod('pre_delete', $doPre);
                
-               BSRegister::GetType('Db')->query("DELETE FROM {$this->prefix}{$this->table} WHERE {$this->condition}");
+               BSApp::$db->query("DELETE FROM {$this->prefix}{$this->table} WHERE {$this->condition}");
                
-               $this->_runActionMethod('post_remove', $doPost);
+               $this->_runActionMethod('post_delete', $doPost);
        }
        
-       // ###################################################################
        /**
-       * Verifies that all required fields are set
-       */
-       private function verify()
+        * Verifies that all required fields are set
+        */
+       protected function _verifyRequired()
        {
-               foreach ($this->fields AS $name => $options)
+               foreach ($this->fields as $name => $options)
                {
                        if ($options[F_REQ] == REQ_YES)
                        {
                                if (!isset($this->values["$name"]))
                                {
-                                       $this->error(sprintf(_('The required field "%1$s" was not set'), $name));
+                                       $this->_error(new FieldException(sprintf(_('The required field "%1$s" was not set'), $name), $name));
                                }
                        }
                        else if ($options[F_REQ] == REQ_SET)
@@ -448,39 +440,37 @@ abstract class BSApi
                }
        }
        
-       // ###################################################################
        /**
-       * Runs a pre- or post-action method for database commands
-       *
-       * @param        string  Action to run
-       * @param        bool    Actually run it?
-       */
-       private function _runActionMethod($method, $doRun)
+        * Runs a pre- or post-action method for database commands
+        *
+        * @param       string  Action to run
+        * @param       bool    Actually run it?
+        */
+       protected function _runActionMethod($method, $doRun)
        {
-               if (!$doRun)
+               if (!$doRun || !method_exists($this, $method))
                {
                        return;
                }
                
-               $actmethod = (method_exists($this, $method) ? $this->$method() : '');
+               $this->$method();
        }
        
-       // ###################################################################
        /**
-       * Prepares a value for use in a SQL query; it encases and escapes
-       * strings and string-like values
-       *
-       * @param        string  Field name
-       *
-       * @return       string  Prepared value entry
-       */
-       private function _prepareFieldForSql($name)
+        * Prepares a value for use in a SQL query; it encases and escapes
+        * strings and string-like values
+        *
+        * @param       string  Field name
+        *
+        * @return      string  Prepared value entry
+        */
+       protected function _prepareFieldForSql($name)
        {
                $type = $this->fields["$name"][F_TYPE];
                
-               if ($type == TYPE_NOCLEAN OR $type == TYPE_STR OR $type == TYPE_STRUN)
+               if ($type == TYPE_NONE || $type == TYPE_STR || $type == TYPE_STRUN)
                {
-                       return "'" . BSRegister::GetType('Db')->escapeString($this->values["$name"]) . "'";
+                       return "'" . BSApp::$db->escapeString($this->values["$name"]) . "'";
                }
                else if ($type == TYPE_BOOL)
                {
@@ -488,7 +478,7 @@ abstract class BSApi
                }
                else if ($type == TYPE_BIN)
                {
-                       return "'" . BSRegister::GetType('Db')->escapeBinary($this->values["$name"]) . "'";
+                       return "'" . BSApp::$db->escapeBinary($this->values["$name"]) . "'";
                }
                else
                {
@@ -496,67 +486,156 @@ abstract class BSApi
                }
        }
        
-       // ###################################################################
        /**
-       * Verify field: not a zero value
-       */
-       protected function verify_nozero($field)
+        * Determines the value of a field from Api->record[], Api->values[] (in that order)
+        *
+        * @param       string  The field ID to determine for
+        *
+        * @return      mixed
+        */
+       public function fetchValue($field)
+       {
+               if ($this->record[$field])
+               {
+                       return $this->record[$field];
+               }
+               else if ($this->values[$field])
+               {
+                       return $this->values[$field];
+               }
+               
+               return null;
+       }
+       
+       /**
+        * Verify field: not a zero value
+        */
+       protected function _verifyIsNotZero($field)
        {
-               if ($this->values["$field"] == 0)
+               if ($this->values[$field] == 0)
                {
-                       return sprintf(_('The field "%1$s" cannot be zero'), $field);
+                       $this->_error(new FieldException(sprintf(_('The field "%1$s" cannot be zero'), $field), $field));
+                       return false;
                }
                
                return true;
        }
        
-       // ###################################################################
        /**
-       * Verify field: not empty
-       */
-       protected function verify_noempty($field)
+        * Verify field: not empty
+        */
+       protected function _verifyIsNotEmpty($field)
        {
-               if (empty($this->values["$field"]))
+               if (empty($this->values[$field]))
                {
-                       return sprintf(_('The field "%1$s" cannot be empty'), $field);
+                       $this->_error(new FieldException(sprintf(_('The field "%1$s" cannot be empty'), $field), $field));
+                       return false;
+               }
+               
+               return true;
+       }
+       
+       /**
+        * Verify field: unique
+        */
+       protected function _verifyIsNotUnique($field)
+       {
+               $res = BSApp::$db->queryFirst("SELECT $field FROM {$this->prefix}{$this->table} WHERE $field = " . $this->_prepareFieldForSql($field) . (empty($this->condition) ? "" : " AND !({$this->condition})"));
+               if ($res)
+               {
+                       $this->_error(new FieldException(sprintf(_('The "%1$s" field must contain a unique value'), $field), $field));
+                       return false;
                }
                
                return true;
        }
 }
 
-// ###################################################################
 /**
-* Setter and getter method for the API error reporting system. Passing
-* a name will cause the set, no arguments will cause the get.
-*
-* @access      public
-*
-* @param       mixed   Method name in callable form
-*
-* @return      mixed   Method name in callable form
-*/
-function APIError($new = null)
+ * API Exception
+ *
+ * This class is an exception container that can be used to store a series
+ * of exceptions that can be thrown as one
+ *
+ * @author             rsesek
+ * @copyright  Copyright (c)2005 - 2009, Blue Static
+ * @package            ISSO
+ *
+ */
+class ApiException extends Exception
 {
-       static $caller, $prev;
+       /**
+        * Array of exceptions
+        * @var array
+        */
+       private $exceptions = array();
        
-       if ($new === -1)
+       /**
+        * Constructor
+        */
+       public function __construct()
        {
-               $caller = $prev;
+               parent::__construct(_('An error occurred while processing the API data. Errors: '));
        }
-       else if ($new !== null)
+       
+       /**
+        * Adds an exception to the collection
+        *
+        * @param       Exception $e
+        */
+       public function addException(Exception $e)
        {
-               $prev = $caller;
-               $caller = $new;
+               $this->exceptions[] = $e;
+               $this->message .= ' (' . sizeof($this->exceptions) . ') ' . $e->getMessage();
        }
        
-       return $caller;
+       /**
+        * Returns an array of all the exceptions in the collection
+        *
+        * @return      array
+        */
+       public function getExceptions()
+       {
+               return $this->exceptions;
+       }
+}
+
+/**
+ * Field Exception
+ *
+ * This exception represents a problem with an API field
+ *
+ * @author             rsesek
+ * @copyright  Copyright (c)2005 - 2009, Blue Static
+ * @package            ISSO
+ *
+ */
+class FieldException extends Exception
+{
+       /**
+        * The name of the erroring field
+        * @var string
+        */
+       private $field;
+       
+       /**
+        * Constructor: create a new exception
+        */
+       public function __construct($error, $field)
+       {
+               $this->field = $field;
+               parent::__construct($error);
+       }
+       
+       /**
+        * Returns the name of the field the exception is for
+        *
+        * @return      string
+        */
+       public function getField()
+       {
+               return $this->field;
+       }
 }
 
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
 ?>
\ No newline at end of file