If you ever receive a message like:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Identifier "request_context" is not defined.' in phar:///.../vendor/silex/silex.phar/vendor/pimple/lib/Pimple.php on line 12And it is not directly about the AsseticExtension in Silex-Extensions,it is probably because some of your code wants access to the url_generator - in my case it was my own Routing-Extension for twig.
First some background informations why it happens.
The problem is that some Extensions - like the url_generator - need access to the requestContext, which is defined after you have already called $app->run(); so in your bootstrap-code that probably has not happened.
The creation of the RequestContext is inside Silex\Application::onKernelRequest (Line may differ - works current master).
There are too solutions to the problem - either you lazyload the url_generator by passing in the app instead of the url_generator and access it only when you really need it or you let Silex run your code inside Silex\Application::onKernelRequest by putting it in a closure as a callback to add it to the dispatcher as a listener for the SilexEvents::BEFORE-Event - which is triggered inside Silex\Application::onKernelRequest.
You liked it ? Link it on your homepage or blog: