Well, thatβs easy.
In app.php simply enter an instance of YourRequest instead of the default value:
require_once __DIR__.'/../app/bootstrap.php.cache'; require_once __DIR__.'/../app/AppKernel.php'; //require_once __DIR__.'/../app/AppCache.php'; use src\YourCompany\YourBundle\YourRequest; $kernel = new AppKernel('prod', false); $kernel->loadClassCache(); //$kernel = new AppCache($kernel); $kernel->handle(YourRequest::createFromGlobals())->send();
Just make sure you extend the standard Request in the YourRequest class.
Should work without additional service definitions.
According to the comments, there are thoughts that this will cause IDE autocompletion problems. Theoretically - it should not be.
In your controller, you simply add a use statement
use src\YourCompany\YourBundle\YourRequest;
And in the action where you go through $request , just define its class:
public function yourAction(YourRequest $request)
This will give you autocomplete.
If you want to receive the request as a service or controller, for the IDE you can also define your class in the doc comment:
$request = $this->getRequest();
source share