szurubooru/src/Enum.php

27 lines
583 B
PHP
Raw Normal View History

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