public static function checkLimits(array $limits, array $params)
{
// All parameters should have limit bounds defined
$undefined_limits = array_diff_key($params, $limits);
if (!empty($undefined_limits)) {
throw new Exception\BadParameterException('Parameter without bounds limit defined: ' . print_r($undefined_limits, true));
}
foreach ($params as $variable => $value) {
// Remove the first character: ( or [
$lower_endpoint = substr($limits[$variable], 0, 1);
// Remove the last character: ) or ]
$upper_endpoint = substr($limits[$variable], -1, 1);
// Set the lower and upper limits: #,#
list($lower_limit, $upper_limit) = explode(',', substr($limits[$variable], 1, -1));
// If the lower limit is -∞, we are always in bounds.
if ($lower_limit != "-∞") {
switch ($lower_endpoint) {
case '(':
if ($value <= $lower_limit) {
throw new Exception\OutOfBoundsException("{$variable} must be > {$lower_limit}");
}
break;
case '[':
if ($value < $lower_limit) {
throw new Exception\OutOfBoundsException("{$variable} must be >= {$lower_limit}");
}
break;
default:
throw new Exception\BadDataException("Unknown lower endpoint character: {$lower_limit}");
}
}
// If the upper limit is ∞, we are always in bounds.
if ($upper_limit != "∞") {
switch ($upper_endpoint) {
case ')':
if ($value >= $upper_limit) {
throw new Exception\OutOfBoundsException("{$variable} must be < {$upper_limit}");
}
break;
case ']':
if ($value > $upper_limit) {
throw new Exception\OutOfBoundsException("{$variable} must be <= {$upper_limit}");
}
break;
default:
throw new Exception\BadDataException("Unknown upper endpoint character: {$upper_endpoint}");
}
}
}
return true;
}