symfony/symfony — pull request #4323 by niklasf (2012-05-18 10:33:02+00:00)
Title: [HttpFoundation] Add a StreamedFileResponse.

In the Drupal 8 branch where we are trying to leverage Symfonys HTTP Kernel we
currently have something like this:

```
function file_download(...) {
// [...]
return new StreamedResponse(function() use ($uri)) {
if (... && fopen($uri, 'rb')) {
while (!feof($fd)) {
print fread($fd, 1024);
}
fclose($fd);
}
}, 200, $headers);
}
```

This is bad because:
- There might be better methods of streaming out a file, like X-Sendfile if
available.
- Code like this is duplicated in different places.

Obvious solution to the latter point: Factor that out to something like a
StreamedFileResponse. Basically, then, the question is why such a class
shouldn't be in Symfony itself.

Heres a sketch of what such a class would have to do. For discussion and as
context for the following questions, without testcoverage or a changelog entry
(yet).

- Generally: Have something like that in Symfony?
- Detail: How to do error handling? Can I throw exceptions from the HttpKernel
component?
- How to best enable the different transfer methods? The switch-case stuff
doesn't look good. How to leverage the dependency injection container or
keep it compatible with that?