For information, we started implementing Request Handler, but not as singleton : it is an abstract class will all static functions.
We also use camelCase naming.
We start using is for new needs and will try and find time to replace all direct call to $_REQUEST with call to functions of this class.
Thnaks for the idea.
abstract class RequestHandler {
public static function getValue($code,$required=false,$default=null) {
if (isset($_REQUEST[$code])) {
return $_REQUEST[$code];
} else {
if ($required) {
throwError("parameter '$code' not found in Request");
exit;
} else {
return $default;
}
}
}
public static function getClass($code,$required=false,$default=null) {
$val=self::getValue($code,$required,$default);
if ($val==$default) return $val;
return Security::checkValidClass($val);
}
public static function getId($code,$required=false,$default=null) {
$val=self::getValue($code,$required,$default);
if ($val==$default) return $val;
return Security::checkValidId($val);
}
public static function getNumeric($code,$required=false,$default=null) {
$val=self::getValue($code,$required,$default);
if ($val==$default) return $val;
return Security::checkValidNumeric($val);
}
public static function getAlphanumeric($code,$required=false,$default=null) {
$val=self::getValue($code,$required,$default);
if ($val==$default) return $val;
return Security::checkValidAlphanumeric($val);
}
public static function getDatetime($code,$required=false,$default=null) {
$val=self::getValue($code,$required,$default);
if ($val==$default) return $val;
return Security::checkValidDateTime($val);
}
public static function getYear($code,$required=false,$default=null) {
$val=self::getValue($code,$required,$default);
if ($val==$default) return $val;
return Security::checkValidYear($val);
}
public static function getMonth($code,$required=false,$default=null) {
$val=self::getValue($code,$required,$default);
if ($val==$default) return $val;
return Security::checkValidMonth($val);
}
public static function getExpected($code,$expectedList) {
$val=self::getValue($code,true,null);
if (in_array($val, $expectedList)) {
return $val;
} else {
throwError("parameter $code='$val' has an unexpected value");
exit;
}
}
}