bug #10797 [HttpFoundation] Allow File instance to be passed to BinaryFileResponse (anlutro)

This PR was merged into the 2.3 branch.

Discussion
----------

[HttpFoundation] Allow File instance to be passed to BinaryFileResponse

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10608
| License       | MIT
| Doc PR        |

See https://github.com/symfony/symfony/issues/10608 for discussion and reasoning.

The docblocks get rather long with this change. The File class does extend SplFileObject so technically it could be left out of the docblock if that is more desirable.

Commits
-------

fc04ad2 Allow File instance to be passed to BinaryFileResponse
This commit is contained in:
Fabien Potencier 2014-04-28 18:47:48 +02:00
commit 9e2a834582
1 changed files with 3 additions and 1 deletions

View File

@ -81,7 +81,9 @@ class BinaryFileResponse extends Response
*/
public function setFile($file, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
{
$file = new File((string) $file);
if (!$file instanceof File) {
$file = new File((string) $file);
}
if (!$file->isReadable()) {
throw new FileException('File must be readable.');