diff options
author | wei <> | 2006-12-04 00:02:23 +0000 |
---|---|---|
committer | wei <> | 2006-12-04 00:02:23 +0000 |
commit | 18ea316c553f7ccfc18b73f0c987de007f11b275 (patch) | |
tree | b8fa0d14de75582b48c3e4d12050c84f07805920 /framework/Data/SqlMap/DataMapper/TSqlMapException.php | |
parent | b69ca04f50ffd538239342f3bfd1e77ffc6156c0 (diff) |
Fixed #469
Diffstat (limited to 'framework/Data/SqlMap/DataMapper/TSqlMapException.php')
-rw-r--r-- | framework/Data/SqlMap/DataMapper/TSqlMapException.php | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapException.php b/framework/Data/SqlMap/DataMapper/TSqlMapException.php new file mode 100644 index 00000000..9a2db478 --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TSqlMapException.php @@ -0,0 +1,99 @@ +<?php
+
+class TSqlMapException extends TException
+{
+ /**
+ * Constructor.
+ * @param string error message. This can be a string that is listed
+ * in the message file. If so, the message in the preferred language
+ * will be used as the error message. Any rest parameters will be used
+ * to replace placeholders ({0}, {1}, {2}, etc.) in the message.
+ */
+ public function __construct($errorMessage)
+ {
+ $this->setErrorCode($errorMessage);
+ $errorMessage=$this->translateErrorMessage($errorMessage);
+ $args=func_get_args();
+ array_shift($args);
+ $n=count($args);
+ $tokens=array();
+ for($i=0;$i<$n;++$i)
+ {
+ if($args[$i] instanceof SimpleXmlElement)
+ $tokens['{'.$i.'}']=$this->implodeNode($args[$i]);
+ else
+ $tokens['{'.$i.'}']=TPropertyValue::ensureString($args[$i]);
+ }
+ parent::__construct(strtr($errorMessage,$tokens));
+ }
+
+ protected function implodeNode($node)
+ {
+ $attributes=array();
+ foreach($node->attributes() as $k=>$v)
+ $attributes[]=$k.'="'.(string)$v.'"';
+ return '<'.$node->getName().' '.implode(' ',$attributes).'>';
+ }
+
+ /**
+ * @return string path to the error message file
+ */
+ protected function getErrorMessageFile()
+ {
+ $lang=Prado::getPreferredLanguage();
+ $dir=dirname(__FILE__);
+ $msgFile=$dir.'/messages-'.$lang.'.txt';
+ if(!is_file($msgFile))
+ $msgFile=$dir.'/messages.txt';
+ return $msgFile;
+ }
+}
+
+class TSqlMapConfigurationException extends TSqlMapException
+{
+
+}
+
+class TUndefinedAttributeException extends TSqlMapConfigurationException
+{
+ public function __construct($attr, $node, $object, $file)
+ {
+ parent::__construct(
+ 'sqlmap_undefined_attribute', get_class($object), $attr,
+ htmlentities($node->asXml()),$file);
+ }
+}
+
+class TSqlMapExecutionException extends TSqlMapException
+{
+}
+
+class TSqlMapQueryExecutionException extends TSqlMapExecutionException
+{
+ protected $parent;
+ public function __construct($statement, $exception)
+ {
+ $this->parent = $exception;
+ parent::__construct('sqlmap_query_execution_error',
+ $statement->getID(), $exception->getMessage());
+ }
+}
+
+class TSqlMapUndefinedException extends TSqlMapException
+{
+
+}
+
+class TSqlMapDuplicateException extends TSqlMapException
+{
+}
+
+class TSqlMapConnectionException extends TSqlMapException
+{
+}
+
+class TInvalidPropertyException extends TSqlMapException
+{
+
+}
+?>
\ No newline at end of file |