例如,我想向 Request 类添加其他方法,例如getRequiered*($name)
在请求中丢失参数的情况下会抛出异常。我想像这样实现它:
class MySmartRequest extends Request {
// ...
function getIntRequired($name) {
$res = $this->get($name, null);
if (null === $res) { throw new Exception('Missed required param'); }
return (int) $res;
}
}
// ...
$app->before(function(Request $r) {
return new MySmartRequest($r);
});
有可能吗?