. // }}} namespace App\Util; use App\Util\Exception\ServerException; abstract class Bitmap { public static $consts = null; public static function bitmapToStrings(int $r): array { $init = $r; $class = get_called_class(); $vals = []; if (self::$consts == null) { self::$consts = (new \ReflectionClass($class))->getConstants(); unset(self::$consts['PREFIX']); } foreach (self::$consts as $c => $v) { if (($r & $v) !== 0) { $r -= $v; $vals[] = $class::PREFIX . $c; } } if ($r != 0) { Log::error('Bitmap to array conversion failed'); throw new ServerException("Bug in bitmap conversion for class {$class} from value {$init}"); } return $vals; } }