Add ServiceStates::int()

This commit is contained in:
Eric Lippmann 2019-11-22 13:42:29 +01:00
parent fb8b843249
commit c600b0640f

View file

@ -17,6 +17,40 @@ class ServiceStates
const PENDING = 99;
/**
* Get the integer value of the given textual service state
*
* @param string $state
*
* @return int
*
* @throws \InvalidArgumentException If the given service state is invalid, i.e. not known
*/
public static function int($state)
{
switch (strtolower($state)) {
case 'ok':
$int = self::OK;
break;
case 'warning':
$int = self::WARNING;
break;
case 'critical':
$int = self::CRITICAL;
break;
case 'unknown':
$int = self::UNKNOWN;
break;
case 'pending':
$int = self::PENDING;
break;
default:
throw new \InvalidArgumentException(sprintf('Invalid service state %d', $state));
}
return $int;
}
/**
* Get the textual representation of the passed service state
*