How to use a custom Request in Symfony

Code
<?php

use Symfony\Component\HttpFoundation\Request;

// Use regular Request class. Manipulate parameters.
$factory = function(array $query, array $request, array $attributes, array $cookies, array $files, array $server$content) {
    
$server['bar'] = 'bar';
    
    return new 
Request($query$request$attributes$cookies$files$server$content);
};

// Use custom Request class.
$fooFactory = function(array $query, array $request, array $attributes, array $cookies, array $files, array $server$content) {
    return new 
FooRequest($query$request$attributes$cookies$files$server$content);
};

class 
FooRequest extends Request
{
    public function 
getFoo()
    {
        return 
'foo';
    }
}


// Create instance of regular Request with parameter manipulation.
Request::setFactory($factory);
$request Request::createFromGlobals();

dump($request->server->get('bar'));

// Create instance of FooRequest
Request::setFactory($fooFactory);
$request Request::createFromGlobals();

dump($request->getFoo());
Result
"bar"

"foo"
Used Versions
PHP 7.1, Zend 3.0, Symfony 3.2, Laravel 5.2, PHPUnit 5.6, Doctrine 2.6