mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 23:59:53 +00:00
PermissionParser: move default string mappings to const array instead of switch
this allows them to be used for validation in stuff like Respect In() rule.
This commit is contained in:
parent
3fb34ad18e
commit
38e28f91e8
@ -31,6 +31,25 @@ use function strtolower;
|
|||||||
|
|
||||||
class PermissionParser{
|
class PermissionParser{
|
||||||
|
|
||||||
|
public const DEFAULT_STRING_MAP = [
|
||||||
|
"op" => Permission::DEFAULT_OP,
|
||||||
|
"isop" => Permission::DEFAULT_OP,
|
||||||
|
"operator" => Permission::DEFAULT_OP,
|
||||||
|
"isoperator" => Permission::DEFAULT_OP,
|
||||||
|
"admin" => Permission::DEFAULT_OP,
|
||||||
|
"isadmin" => Permission::DEFAULT_OP,
|
||||||
|
|
||||||
|
"!op" => Permission::DEFAULT_NOT_OP,
|
||||||
|
"notop" => Permission::DEFAULT_NOT_OP,
|
||||||
|
"!operator" => Permission::DEFAULT_NOT_OP,
|
||||||
|
"notoperator" => Permission::DEFAULT_NOT_OP,
|
||||||
|
"!admin" => Permission::DEFAULT_NOT_OP,
|
||||||
|
"notadmin" => Permission::DEFAULT_NOT_OP,
|
||||||
|
|
||||||
|
"true" => Permission::DEFAULT_TRUE,
|
||||||
|
"false" => Permission::DEFAULT_FALSE,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool|string $value
|
* @param bool|string $value
|
||||||
*
|
*
|
||||||
@ -44,27 +63,9 @@ class PermissionParser{
|
|||||||
return "false";
|
return "false";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch(strtolower($value)){
|
$lower = strtolower($value);
|
||||||
case "op":
|
if(isset(self::DEFAULT_STRING_MAP[$lower])){
|
||||||
case "isop":
|
return self::DEFAULT_STRING_MAP[$lower];
|
||||||
case "operator":
|
|
||||||
case "isoperator":
|
|
||||||
case "admin":
|
|
||||||
case "isadmin":
|
|
||||||
return Permission::DEFAULT_OP;
|
|
||||||
|
|
||||||
case "!op":
|
|
||||||
case "notop":
|
|
||||||
case "!operator":
|
|
||||||
case "notoperator":
|
|
||||||
case "!admin":
|
|
||||||
case "notadmin":
|
|
||||||
return Permission::DEFAULT_NOT_OP;
|
|
||||||
|
|
||||||
case "true":
|
|
||||||
return Permission::DEFAULT_TRUE;
|
|
||||||
case "false":
|
|
||||||
return Permission::DEFAULT_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException("Unknown permission default name \"$value\"");
|
throw new \InvalidArgumentException("Unknown permission default name \"$value\"");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user