diff options
author | xue <> | 2006-04-07 19:07:14 +0000 |
---|---|---|
committer | xue <> | 2006-04-07 19:07:14 +0000 |
commit | 325b2ab61e3cf03e9ae7fb03ee1030cae6b08b3e (patch) | |
tree | dcd1adebecc1f0270872f0f8e78c6d4601c6499a | |
parent | 1d94593d09b68786f7035e7b06ec6d8324894d77 (diff) |
Removed TDataValueFormatter.
-rw-r--r-- | .gitattributes | 1 | ||||
-rw-r--r-- | HISTORY | 1 | ||||
-rw-r--r-- | framework/Exceptions/messages.txt | 3 | ||||
-rw-r--r-- | framework/Util/TDataValueFormatter.php | 67 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TDataGridColumn.php | 30 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TListControl.php | 41 |
6 files changed, 64 insertions, 79 deletions
diff --git a/.gitattributes b/.gitattributes index 0846c876..e3cb02e2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -668,7 +668,6 @@ framework/TComponent.php -text framework/TModule.php -text framework/TService.php -text framework/Util/TDataFieldAccessor.php -text -framework/Util/TDataValueFormatter.php -text framework/Util/TLogRouter.php -text framework/Util/TLogger.php -text framework/Util/TParameterModule.php -text @@ -2,7 +2,6 @@ Version 3.1.0 To be released ============================
ENH: Format string in classes extending TDataGridColumn can now evaluate an expression (Qiang)
ENH: Format string in classes extending TListControl can now evaluate an expression (Qiang)
-NEW: TDataValueFormatter class (Qiang)
Version 3.0RC2 April 16, 2006
=============================
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt index 6e2d676f..7cf25c75 100644 --- a/framework/Exceptions/messages.txt +++ b/framework/Exceptions/messages.txt @@ -183,6 +183,7 @@ webcontrol_style_invalid = {0}.Style must take string value only. listcontrol_selection_invalid = {0} has an invalid selection that is set before performing databinding.
listcontrol_selectedindex_invalid = {0}.SelectedIndex has an invalid value {1}.
listcontrol_selectedvalue_invalid = {0}.SelectedValue has an invalid value '{1}'.
+listcontrol_expression_invalid = {0} is evaluating an invalid expression '{1}' : {2}
label_associatedcontrol_invalid = TLabel.AssociatedControl '{0}' cannot be found.
@@ -279,4 +280,4 @@ parametermodule_parameterfile_unchangeable = TParameterModule.ParameterFile is n parametermodule_parameterfile_invalid = TParameterModule.ParameterFile '{0}' is invalid. Make sure it is in namespace format and the file extension is '.xml'.
parametermodule_parameterid_required = Parameter element must have 'id' attribute.
-datagridcolumn_expression_invalid = {0} is evaluating an invalid expression "{1}" : {2}
\ No newline at end of file +datagridcolumn_expression_invalid = {0} is evaluating an invalid expression '{1}' : {2}
\ No newline at end of file diff --git a/framework/Util/TDataValueFormatter.php b/framework/Util/TDataValueFormatter.php deleted file mode 100644 index 797a88d1..00000000 --- a/framework/Util/TDataValueFormatter.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php
-/**
- * TDataValueFormatter class file
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright © 2005 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Revision: $ $Date: $
- * @package System.Util
- */
-
-/**
- * TDataValueFormatter class
- *
- * TDataValueFormatter is a utility class that formats a data value
- * according to a format string.
- *
- * @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Revision: $ $Date: $
- * @package System.Util
- * @since 3.0
- */
-class TDataValueFormatter
-{
- /**
- * Formats the text value according to a format string.
- * If the format string is empty, the original value is converted into
- * a string and returned.
- * If the format string starts with '#', the string is treated as a PHP expression
- * within which the token '{0}' is translated with the data value to be formated.
- * Otherwise, the format string and the data value are passed
- * as the first and second parameters in {@link sprintf}.
- * @param string format string
- * @param mixed the data associated with the cell
- * @param TComponent the context to evaluate the expression
- * @return string the formatted result
- */
- public static function format($formatString,$value,$context=null)
- {
- if($formatString==='')
- return TPropertyValue::ensureString($value);
- else if($formatString[0]==='#')
- {
- $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
- if($context instanceof TComponent)
- return $context->evaluateExpression($expression);
- else
- {
- try
- {
- if(eval("\$result=$expression;")===false)
- throw new Exception('');
- return $result;
- }
- catch(Exception $e)
- {
- throw new TInvalidOperationException('datavalueformatter_expression_invalid',$expression,$e->getMessage());
- }
- }
- }
- else
- return sprintf($formatString,$value);
- }
-}
-
-?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TDataGridColumn.php b/framework/Web/UI/WebControls/TDataGridColumn.php index ea825360..e43b4895 100644 --- a/framework/Web/UI/WebControls/TDataGridColumn.php +++ b/framework/Web/UI/WebControls/TDataGridColumn.php @@ -14,7 +14,6 @@ * Includes TDataFieldAccessor and TDataValueFormatter classes
*/
Prado::using('System.Util.TDataFieldAccessor');
-Prado::using('System.Util.TDataValueFormatter');
/**
* TDataGridColumn class
@@ -333,15 +332,36 @@ abstract class TDataGridColumn extends TApplicationComponent /**
* Formats the text value according to a format string.
- * It uses {@link TDataValueFormatter} to do the actual formatting.
+ * If the format string is empty, the original value is converted into
+ * a string and returned.
+ * If the format string starts with '#', the string is treated as a PHP expression
+ * within which the token '{0}' is translated with the data value to be formated.
+ * Otherwise, the format string and the data value are passed
+ * as the first and second parameters in {@link sprintf}.
* @param string format string
- * @param mixed the data associated with the cell
+ * @param mixed the data to be formatted
* @return string the formatted result
- * @see TDataValueFormatter::format()
*/
protected function formatDataValue($formatString,$value)
{
- return TDataValueFormatter::format($formatString,$value,$this);
+ if($formatString==='')
+ return TPropertyValue::ensureString($value);
+ else if($formatString[0]==='#')
+ {
+ $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
+ try
+ {
+ if(eval("\$result=$expression;")===false)
+ throw new Exception('');
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ throw new TInvalidDataValueException('datagridcolumn_expression_invalid',get_class($this),$expression,$e->getMessage());
+ }
+ }
+ else
+ return sprintf($formatString,$value);
}
}
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php index 5c1e9083..1c615edc 100644 --- a/framework/Web/UI/WebControls/TListControl.php +++ b/framework/Web/UI/WebControls/TListControl.php @@ -16,7 +16,6 @@ Prado::using('System.Web.UI.WebControls.TDataBoundControl');
Prado::using('System.Collections.TAttributeCollection');
Prado::using('System.Util.TDataFieldAccessor');
-Prado::using('System.Util.TDataValueFormatter');
/**
@@ -70,8 +69,8 @@ Prado::using('System.Util.TDataValueFormatter'); * to 'name' and 'age' will make the first item's text be 'John', value be 31,
* the second item's text be 'Cary', value be 28, and so on.
* The {@link setDataTextFormatString DataTextFormatString} property may be further
- * used to format how the item should be displayed. The formatting function is
- * {@link TDataValueFormatter::format()}.
+ * used to format how the item should be displayed. See {@link formatDataValue()}
+ * for an explanation of the format string.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
@@ -188,7 +187,7 @@ abstract class TListControl extends TDataBoundControl $text=$object;
$item->setValue("$key");
}
- $item->setText(TDataValueFormatter::format($textFormat,$text,$this));
+ $item->setText($this->formatDataValue($textFormat,$text));
$items->add($item);
}
// SelectedValue or SelectedIndex may be set before databinding
@@ -582,6 +581,40 @@ abstract class TListControl extends TDataBoundControl }
}
}
+
+ /**
+ * Formats the text value according to a format string.
+ * If the format string is empty, the original value is converted into
+ * a string and returned.
+ * If the format string starts with '#', the string is treated as a PHP expression
+ * within which the token '{0}' is translated with the data value to be formated.
+ * Otherwise, the format string and the data value are passed
+ * as the first and second parameters in {@link sprintf}.
+ * @param string format string
+ * @param mixed the data to be formatted
+ * @return string the formatted result
+ */
+ protected function formatDataValue($formatString,$value)
+ {
+ if($formatString==='')
+ return TPropertyValue::ensureString($value);
+ else if($formatString[0]==='#')
+ {
+ $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
+ try
+ {
+ if(eval("\$result=$expression;")===false)
+ throw new Exception('');
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ throw new TInvalidDataValueException('listcontrol_expression_invalid',get_class($this),$expression,$e->getMessage());
+ }
+ }
+ else
+ return sprintf($formatString,$value);
+ }
}
/**
|