self::DEFAULT_OP, "isop" => self::DEFAULT_OP, "operator" => self::DEFAULT_OP, "isoperator" => self::DEFAULT_OP, "admin" => self::DEFAULT_OP, "isadmin" => self::DEFAULT_OP, "!op" => self::DEFAULT_NOT_OP, "notop" => self::DEFAULT_NOT_OP, "!operator" => self::DEFAULT_NOT_OP, "notoperator" => self::DEFAULT_NOT_OP, "!admin" => self::DEFAULT_NOT_OP, "notadmin" => self::DEFAULT_NOT_OP, "true" => self::DEFAULT_TRUE, "false" => self::DEFAULT_FALSE, ]; /** * @param bool|string $value * * @throws \InvalidArgumentException */ public static function defaultFromString($value) : string{ if(is_bool($value)){ if($value){ return "true"; }else{ return "false"; } } $lower = strtolower($value); if(isset(self::DEFAULT_STRING_MAP[$lower])){ return self::DEFAULT_STRING_MAP[$lower]; } throw new \InvalidArgumentException("Unknown permission default name \"$value\""); } /** * @param mixed[][] $data * @phpstan-param array> $data * * @return Permission[][] * @phpstan-return array> */ public static function loadPermissions(array $data, string $default = self::DEFAULT_FALSE) : array{ $result = []; foreach($data as $key => $entry){ self::loadPermission($key, $entry, $default, $result); } return $result; } /** * @param mixed[] $data * @param Permission[][] $output reference parameter * @phpstan-param array $data * @phpstan-param array> $output * * @throws \Exception */ public static function loadPermission(string $name, array $data, string $default = self::DEFAULT_FALSE, array &$output = []) : void{ $desc = null; if(isset($data["default"])){ $default = PermissionParser::defaultFromString($data["default"]); } if(isset($data["children"])){ throw new \InvalidArgumentException("Nested permission declarations are no longer supported. Declare each permission separately."); } if(isset($data["description"])){ $desc = $data["description"]; } $output[$default][] = new Permission($name, $desc); } }