Symfony has a pretty clear code example on how to override the request class, but I do not know where in my App I should place it. I receive the request object from Symfony in my controller actions and want to get the SpecialRequest Object instead.
I already tried a kernel.request listener, but this seems to be too late. Is there a place where this kind of initialization code would fit?
Request::setFactory(function (
array $query = array(),
array $request = array(),
array $attributes = array(),
array $cookies = array(),
array $files = array(),
array $server = array(),
$content = null
) {
return SpecialRequest::create(
$query,
$request,
$attributes,
$cookies,
$files,
$server,
$content
);
});
http://symfony.com/doc/current/components/http_foundation/introduction.html#overriding-the-request
In the example given, the Request::setFactory method is called immediately prior to calling the Request::createFromGlobals method. This would imply that the appropriate place for calling this method would be in the front controller, e.g. app.php, app_dev.php and any other file used as a front controller.
In fact the Request::createFromGlobals method and the Request::create method check to see whether a callable has been set by the Request::setFactory method, and if so they use this callable to create an object that should extend the Request class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With