use Symfony\Component\HttpFoundation\Response; $response = new Response('Hello world!', Response::HTTP_OK); $response->send();
use Symfony\Component\HttpFoundation\Response; $response = new Response('Hello world!'); $response->headers->set('Content-Type', 'text/plain'); $response->headers->set('X-Example-Header', 'some-value'); $response->send();
use Symfony\Component\HttpFoundation\Response; $fileContents = file_get_contents('/path/to/myfile.txt'); $response = new Response($fileContents); $response->headers->set('Content-Type', 'text/plain'); $response->headers->set('Content-Disposition', 'attachment; filename="myfile.txt"'); $response->send();This code reads the contents of a file and creates a new Response object. It sets the headers to specify that the content should be downloaded as an attachment with a specific filename. The Response class is part of the Symfony HTTP Foundation component, which provides a set of classes for working with HTTP requests and responses.