DeltaCMS/src/Classes/Enum.php
Florian Bouillon e4d59be18c many changes
updated composer.json to user psr-4 autoloader
updated .htaccess to point to the correct file
Rewrite of most of the project
2019-03-14 23:24:04 +01:00

47 lines
1.2 KiB
PHP

<?php
namespace AdminPanel\Classes\Enum;
abstract class Enum {
/** @var null|array $constCacheArray */
private static $constCacheArray = NULL;
private static function getConstants() {
if (self::$constCacheArray == NULL) {
self::$constCacheArray = [];
}
$calledClass = get_called_class();
if (!array_key_exists($calledClass, self::$constCacheArray)) {
$reflect = new ReflectionClass($calledClass);
self::$constCacheArray[$calledClass] = $reflect->getConstants();
}
return self::$constCacheArray[$calledClass];
}
public static function isValidName($name, $strict = false) {
$constants = self::getConstants();
if ($strict) {
return array_key_exists($name, $constants);
}
$keys = array_map('strtolower', array_keys($constants));
return in_array(strtolower($name), $keys);
}
public static function isValidValue($value, $strict = true) {
$values = array_values(self::getConstants());
return in_array($value, $values, $strict);
}
}
// abstract class DaysOfWeek extends BasicEnum {
// const Sunday = 0;
// const Monday = 1;
// const Tuesday = 2;
// const Wednesday = 3;
// const Thursday = 4;
// const Friday = 5;
// const Saturday = 6;
// }