From 55c4ac1bfe565f1ca7f537fdd8b7a201be28e581 Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 10 Nov 2005 12:47:19 +0000 Subject: Initial import of prado framework --- framework/Exceptions/TErrorHandler.php | 48 +++++++++ framework/Exceptions/TException.php | 175 +++++++++++++++++++++++++++++++++ framework/Exceptions/messages.en | 28 ++++++ 3 files changed, 251 insertions(+) create mode 100644 framework/Exceptions/TErrorHandler.php create mode 100644 framework/Exceptions/TException.php create mode 100644 framework/Exceptions/messages.en (limited to 'framework/Exceptions') diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php new file mode 100644 index 00000000..458d3169 --- /dev/null +++ b/framework/Exceptions/TErrorHandler.php @@ -0,0 +1,48 @@ +attachEventHandler('Error',array($this,'handle')); + $this->_initialized=true; + } + + /** + * @return string id of this module + */ + public function getID() + { + return $this->_id; + } + + /** + * @param string id of this module + */ + public function setID($value) + { + $this->_id=$value; + } + + public function handle($sender,$param) + { echo '...........................'; + echo $param; + } +} + +?> \ No newline at end of file diff --git a/framework/Exceptions/TException.php b/framework/Exceptions/TException.php new file mode 100644 index 00000000..0c51e1f1 --- /dev/null +++ b/framework/Exceptions/TException.php @@ -0,0 +1,175 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Exceptions + */ + +/** + * TException class + * + * TException is the base class for all PRADO exceptions. + * TException + * TSystemException + * TNullReferenceException + * TIndexOutOfRangeException + * TArithmeticException + * TInvalidValueException + * TInvalidTypeException + * TInvalidFormatException + * TInvalidOperationException + * TConfigurationException + * TSecurityException + * TIOException + * TDBException + * THttpException + * TNotSupportedException + * TApplicationException + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Exceptions + * @since 3.0 + */ +class TException extends Exception +{ + private $_errorCode=''; + + public function __construct($errorCode) + { + $this->_errorCode=$errorCode; + $args=func_get_args(); + $args[0]=$this->translateErrorCode($errorCode); + $str=call_user_func_array('sprintf',$args); + parent::__construct($str); + } + + protected function translateErrorCode($key) + { + // $msgFile=dirname(__FILE__).'/messages.'.Prado::getLocale(); + // if(!is_file($msgFile)) + $msgFile=dirname(__FILE__).'/messages.en'; + if(($entries=@file($msgFile))===false) + return $key; + else + { + foreach($entries as $entry) + { + @list($code,$message)=explode('=',$entry,2); + if(trim($code)===$key) + return trim($message); + } + return $key; + } + } + + public function getErrorCode() + { + return $this->_errorCode; + } + + public function setErrorCode($errorCode) + { + $this->_errorCode=$errorCode; + } + + public function getErrorMessage() + { + return $this->getMessage(); + } + + public function setErrorMessage($msg) + { + $this->message=$msg; + } +} + +class TSystemException extends TException +{ +} + +class TApplicationException extends TException +{ +} + +class TNullReferenceException extends TSystemException +{ +} + +class TIndexOutOfRangeException extends TSystemException +{ +} + +class TArithmeticException extends TSystemException +{ +} + +class TInvalidOperationException extends TSystemException +{ +} + +class TInvalidDataTypeException extends TSystemException +{ +} + +class TInvalidDataValueException extends TSystemException +{ +} + +class TInvalidDataFormatException extends TSystemException +{ +} + +class TConfigurationException extends TSystemException +{ +} + +class TIOException extends TException +{ +} + +class TDBException extends TException +{ +} + +class TSecurityException extends TException +{ +} + +class THttpException extends TException +{ +} + +class TNotSupportedException extends TException +{ +} + +class TPhpErrorException extends TException +{ + public function __construct($errno,$errstr,$errfile,$errline) + { + static $errorTypes=array( + E_ERROR => "Error", + E_WARNING => "Warning", + E_PARSE => "Parsing Error", + E_NOTICE => "Notice", + E_CORE_ERROR => "Core Error", + E_CORE_WARNING => "Core Warning", + E_COMPILE_ERROR => "Compile Error", + E_COMPILE_WARNING => "Compile Warning", + E_USER_ERROR => "User Error", + E_USER_WARNING => "User Warning", + E_USER_NOTICE => "User Notice", + E_STRICT => "Runtime Notice" + ); + $errorType=isset($errorTypes[$errno])?$errorTypes[$errno]:'Unknown Error'; + parent::__construct("[$errorType] $errstr (@line $errline in file $errfile)."); + } +} + +?> \ No newline at end of file diff --git a/framework/Exceptions/messages.en b/framework/Exceptions/messages.en new file mode 100644 index 00000000..d949d88a --- /dev/null +++ b/framework/Exceptions/messages.en @@ -0,0 +1,28 @@ +body_contents_not_allowed = %s: body contents are not allowed. +control_id_not_unique = Control ID '%s' is not unique for control type '%s'. +control_not_found = Unable to find a control with ID '%s'. +control_not_in_form = Control '%s' is not enclosed within a server form. +data_not_iterable = Data is not iterable. An array or an object implementing Traversable is required. +event_not_defined = %s: event is not defined. +expecting_closing_tag = Line %d: expecting closing tag %s. +index_out_of_range = Index '%s' is out of range. +invalid_accesskey = %s.AccessKey: only one character is allowed. +invalid_control_id = Invalid control ID '%s' for control type '%s'. +invalid_enum_value = Invalid value '%s' for enumeration type (%s) +invalid_event_handler = Invalid event handler '%s' for event '%s'. +invalid_expression = Invalid expression '%s': %s. +invalid_statements = Invalid statements '%s': %s. +invalid_subproperty = Invalid sub-property '%s'. +invalid_style_value = %s.Style: only string is allowed. +multiple_form_not_allowed = Multiple server forms are not allowed. +must_be_component = %s must extend from TComponent. +no_comments_in_property = Line %d: comments are not allowed in property values. +property_not_defined = %s: property is not defined. +property_read_only = %s: property is read-only. +skinid_set_after_applied = %s: SkinID cannot be set after the skin is applied. +skinid_set_after_preinit = %s: SkinID cannot be set after PreInit stage. +stylesheet_applied = %s: StyleSheet skin is already applied. +enabletheming_after_preinit = %s: EnableTheme cannot be set after PreInit stage. +nonunique_template_directive = Line %d: at most one template directive is allowed. +unexpected_closing_tag = Line %d: unexpected closing tag %s. +unexpected_matching = Unexpected matching: %s. Please report this problem to PRADO developer team. -- cgit v1.2.3