Last Updated: February 25, 2016
· raphaelstolt

Lower case all request query parameter keys in a Silex application

To avoid case sensitive query parameter names/keys, which might lead to misses when pulling data via $request->get('fooBar'), the following transformation placed in a Silex middleware comes in handy.

use Symfony\Component\HttpFoundation\Request;

$app->before(function (Request $request) {

Afterwards the query parameter values can be pulled, without a miss, via $request->get('foobar') even when the request has been made via ?fooBar=baz or even ?FooBar=baz.