szurubooru/src/Enum.php
2014-05-07 17:58:23 +02:00

26 lines
583 B
PHP

<?php
abstract class Enum
{
public abstract function toString();
public function _toString($constant)
{
$cls = new ReflectionClass(get_called_class());
$constants = $cls->getConstants();
return array_search($constant, $constants);
}
public function toDisplayString()
{
return TextCaseConverter::convert($this->toString(),
TextCaseConverter::CAMEL_CASE,
TextCaseConverter::BLANK_CASE);
}
public static function getAllConstants()
{
$cls = new ReflectionClass(get_called_class());
$constants = $cls->getConstants();
return array_values($constants);
}
}