Symfony internally processes the request using the http_kernel component. That way, you can simulate a request for each batch action that you want to perform, and then pass it to the http_kernel component, and then develop the result.
Consider this example controller:
/** * @Route("/batchAction", name="batchAction") */ public function batchAction() { // Simulate a batch request of existing route $requests = [ [ 'method' => 'GET', 'relative_url' => '/b', 'options' => 'a=b&cd', ], [ 'method' => 'GET', 'relative_url' => '/c', 'options' => 'a=b&cd', ], ]; $kernel = $this->get('http_kernel'); $responses = []; foreach($requests as $aRequest){ // Construct a query params. Is only an example i don't know your input $options=[]; parse_str($aRequest['options'], $options); // Construct a new request object for each batch request $req = Request::create( $aRequest['relative_url'], $aRequest['method'], $options ); // process the request // TODO handle exception $response = $kernel->handle($req); $responses[] = [ 'method' => $aRequest['method'], 'url' => $aRequest['relative_url'], 'code' => $response->getStatusCode(), 'headers' => $response->headers, 'body' => $response->getContent() ]; } return new JsonResponse($responses); }
With the following controller method:
public function aAction(Request $request) { return new Response('A'); } public function bAction(Request $request) { return new Response('B'); } public function cAction(Request $request) { return new Response('C'); }
The query output will be:
[ {"method":"GET","url":"\/b","code":200,"headers":{},"body":"B"}, {"method":"GET","url":"\/c","code":200,"headers":{},"body":"C"} ]
PS: I hope I understand correctly what you need.