diff options
| author | xue <> | 2006-01-01 23:09:47 +0000 | 
|---|---|---|
| committer | xue <> | 2006-01-01 23:09:47 +0000 | 
| commit | cb54d4b2bc36e098e38a25a29a844e726fa501ad (patch) | |
| tree | 16e757761c52f021e1af606cbe4dbfb90481f9d3 /framework | |
| parent | f9f431ec8e564465d08a18d9b402ed8643841fa1 (diff) | |
Enhanced TPropertyValue::ensureEnum() method so that it can take variable length of parameters as valid enumeration values.
Diffstat (limited to 'framework')
| -rw-r--r-- | framework/TComponent.php | 21 | 
1 files changed, 15 insertions, 6 deletions
| diff --git a/framework/TComponent.php b/framework/TComponent.php index 432dba66..0befc27f 100644 --- a/framework/TComponent.php +++ b/framework/TComponent.php @@ -601,18 +601,27 @@ class TPropertyValue  	/**
  	 * Converts a value to enum type.
 -	 * Note, enumeration values are case-sensitive strings.
 +	 * 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.
  	 * @param mixed the value to be converted.
 -	 * @param array array of strings representing the enum type.
 -	 * @return string
 +	 * @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.
 +	 * @return string the valid enumeration value
  	 * @throws TInvalidDataValueException if the original value is not in the string array.
  	 */
 -	public static function ensureEnum($value,$enum)
 +	public static function ensureEnum($value,$enums)
  	{
 -		if(in_array($value,$enum))
 +		if(!is_array($enums))
 +		{
 +			$enums=func_get_args();
 +			array_shift($enums);
 +		}
 +		if(in_array($value,$enums,true))
  			return $value;
  		else
 -			throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid',$value,implode(' | ',$enum));
 +			throw new TInvalidDataValueException('propertyvalue_enumvalue_invalid',$value,implode(' | ',$enums));
  	}
  }
 | 
