summaryrefslogtreecommitdiff
path: root/framework/TComponent.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/TComponent.php')
-rw-r--r--framework/TComponent.php54
1 files changed, 21 insertions, 33 deletions
diff --git a/framework/TComponent.php b/framework/TComponent.php
index b9dbd3d5..986a0b32 100644
--- a/framework/TComponent.php
+++ b/framework/TComponent.php
@@ -594,21 +594,33 @@ class TPropertyValue
/**
* Converts a value to enum type.
- * This method is deprecated. Try to use {@link ensureEnumerable}, instead.
- * This method mainly performs sanity check of a value to make sure
- * it is a valid enumeration value. Each enumeration value is a string
- * which is case-sensistive.
+ *
+ * This method checks if the value is of the specified enumerable type.
+ * A value is a valid enumerable value if it is equal to the name of a constant
+ * in the specified enumerable type (class).
+ * For more details about enumerable, see {@link TEnumerable}.
+ *
+ * For backward compatibility, this method also supports sanity
+ * check of a string value to see if it is among the given list of strings.
* @param mixed the value to be converted.
- * @param mixed array of valid enumeration values. If this is not an array,
- * the method considers its parameters are of variable length, and the second
- * till the last parameters are enumeration values.
+ * @param mixed class name of the enumerable type, or array of valid enumeration values. If this is not an array,
+ * the method considers its parameters are of variable length, and the second till the last parameters are enumeration values.
* @return string the valid enumeration value
* @throws TInvalidDataValueException if the original value is not in the string array.
- * @deprecated deprecated since version 3.0.4
*/
public static function ensureEnum($value,$enums)
{
- if(!is_array($enums))
+ static $types=array();
+ if(func_num_args()===2 && is_string($enums))
+ {
+ if(!isset($types[$enums]))
+ $types[$enums]=new ReflectionClass($enums);
+ if($types[$enums]->hasConstant($value))
+ return $value;
+ else
+ throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid',$value,$enums);
+ }
+ else if(!is_array($enums))
{
$enums=func_get_args();
array_shift($enums);
@@ -618,30 +630,6 @@ class TPropertyValue
else
throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid',$value,implode(' | ',$enums));
}
-
- /**
- * Converts a value to enum type.
- * This method checks if the value is of the specified enumerable type.
- * A value is a valid enumerable value if it is equal to the name of a constant
- * in the specified enumerable type (class).
- * For more details about enumerable, see {@link TEnumerable}.
- * @param string enumerable value
- * @param string enumerable class name
- * @return string valid enumerable value
- * @throws TInvalidDataValueException if the original value is not a valid enumerable value.
- * @see ensureEnum
- * @sine 3.0.4
- */
- public static function ensureEnumerable($value,$enumType)
- {
- static $types=array();
- if(!isset($types[$enumType]))
- $types[$enumType]=new ReflectionClass($enumType);
- if($types[$enumType]->hasConstant($value))
- return $value;
- else
- throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid',$value,$enumType);
- }
}
/**