Prado\TPropertyValue::ensureEnum PHP Метод

ensureEnum() публичный статический Метод

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.
public static ensureEnum ( $value, $enums ) : string
Результат string the valid enumeration value
    public static function ensureEnum($value, $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, implode(' | ', $types[$enums]->getConstants()));
            }
        } else {
            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(' | ', $enums));
        }
    }

Usage Example

Пример #1
0
 /**
  * @param TUserManagerPasswordMode how password is stored, clear text, or MD5 or SHA1 hashed.
  */
 public function setPasswordMode($value)
 {
     $this->_passwordMode = TPropertyValue::ensureEnum($value, 'Prado\\Security\\TUserManagerPasswordMode');
 }
All Usage Examples Of Prado\TPropertyValue::ensureEnum