22declare(strict_types=1);
28use
function strtolower;
32 public const DEFAULT_OP =
"op";
33 public const DEFAULT_NOT_OP =
"notop";
34 public const DEFAULT_TRUE =
"true";
35 public const DEFAULT_FALSE =
"false";
37 public const DEFAULT_STRING_MAP = [
38 "op" => self::DEFAULT_OP,
39 "isop" => self::DEFAULT_OP,
40 "operator" => self::DEFAULT_OP,
41 "isoperator" => self::DEFAULT_OP,
42 "admin" => self::DEFAULT_OP,
43 "isadmin" => self::DEFAULT_OP,
45 "!op" => self::DEFAULT_NOT_OP,
46 "notop" => self::DEFAULT_NOT_OP,
47 "!operator" => self::DEFAULT_NOT_OP,
48 "notoperator" => self::DEFAULT_NOT_OP,
49 "!admin" => self::DEFAULT_NOT_OP,
50 "notadmin" => self::DEFAULT_NOT_OP,
52 "true" => self::DEFAULT_TRUE,
53 "false" => self::DEFAULT_FALSE,
56 private const KEY_DEFAULT =
"default";
57 private const KEY_CHILDREN =
"children";
58 private const KEY_DESCRIPTION =
"description";
65 return $value ? self::DEFAULT_TRUE : self::DEFAULT_FALSE;
67 $lower = strtolower($value);
68 if(isset(self::DEFAULT_STRING_MAP[$lower])){
69 return self::DEFAULT_STRING_MAP[$lower];
72 throw new PermissionParserException(
"Unknown permission default name \"$value\"");
83 public static function loadPermissions(array $data,
string $default = self::DEFAULT_FALSE) : array{
87 if(isset($entry[self::KEY_DEFAULT])){
91 if(isset($entry[self::KEY_CHILDREN])){
92 throw new PermissionParserException(
"Nested permission declarations are no longer supported. Declare each permission separately.");
95 if(isset($entry[self::KEY_DESCRIPTION])){
96 $desc = $entry[self::KEY_DESCRIPTION];
99 $result[$default][] =
new Permission($name, $desc);
static defaultFromString(bool|string $value)
static loadPermissions(array $data, string $default=self::DEFAULT_FALSE)
static stringifyKeys(array $array)