php - Decorate or extend HTTP request class in Silex -
in example, want add additional methods request class, getrequiered*($name) throw exception in case of missed param in request. i'd implement this: 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); }); is possilbe? yes, possible (never done this, following tip reading code). you'll need create subclass of silex\application , , overwrite run() function this: public function run(request $request = null) { if (null === $request) { $request = mysmartrequest::createfromglobals(); } $response = $this->handle($request); $response->send(); $this->terminate($request, $response); } to avoid duplication, can try this: public function run(request $...