*/ public static function all(): array { return array( self::READ_ONLY, self::CONTENT_EDITOR, self::STORE_EDITOR ); } /** * Whether a string is one of the three valid levels. * * @param string $level Candidate level. * @return bool */ public static function isValid( string $level ): bool { return in_array( $level, self::all(), true ); } /** * A level's rank, lowest first. Unknown values rank below every real * level so an invalid level can never accidentally satisfy a comparison. * * @param string $level Level to rank. * @return int -1 for an unknown level, otherwise its index in {@see all()}. */ public static function rank( string $level ): int { $index = array_search( $level, self::all(), true ); return false === $index ? -1 : $index; } /** * Whether $level meets or exceeds $required. False whenever either * value is invalid, so an unknown level never satisfies any requirement * and a connection can never be checked against an unknown requirement. * * @param string $level Level to check. * @param string $required Minimum level required. * @return bool */ public static function atLeast( string $level, string $required ): bool { if ( ! self::isValid( $level ) || ! self::isValid( $required ) ) { return false; } return self::rank( $level ) >= self::rank( $required ); } }