szurubooru/src/Enum.php

25 lines
558 B
PHP
Raw Normal View History

2013-10-07 23:17:33 +02:00
<?php
class Enum
{
public static function toString($constant)
{
$cls = new ReflectionClass(get_called_class());
$constants = $cls->getConstants();
return array_search($constant, $constants);
}
2013-10-08 22:59:32 +02:00
2014-04-12 16:22:30 +02:00
public static function toDisplayString($constant)
{
return TextCaseConverter::convert(static::toString($constant),
2014-04-12 16:22:30 +02:00
TextCaseConverter::SNAKE_CASE,
TextCaseConverter::BLANK_CASE);
}
2013-10-08 22:59:32 +02:00
public static function getAll()
{
$cls = new ReflectionClass(get_called_class());
$constants = $cls->getConstants();
return array_values($constants);
}
2013-10-07 23:17:33 +02:00
}