esky / enum
PHP 枚举实现
1.1.1
2015-05-17 09:47 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 3.7.23
This package is not auto-updated.
Last update: 2024-09-24 07:55:27 UTC
README
##文档
构造函数
$type = new Type(Type::BASIC); $type = Type::createFromConstantName('BASIC'); $type = Type::BASIC(); new Type(5); // InvalidArgumentException
实例方法
$type->getValue(); // 1 $type->getName(); // BASIC $type->isEqual($type); // true $type->isEqual(Type::Basic); // true
静态方法
Type::getValues(); // [1, 2] Type::getNames(); // [1 => 'BASIC', 2 => 'COMPLEX'] Type::getNames([2]); // [2 => 'COMPLEX'] Type::isValidValue(1); // true Type::isValidValue(3); // false
处理空值
$nullType = new Type(null); $nullType->getName(); // null $nullType->getValue(); // null