-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Add file helper to Controller #18502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
c2e7917
[FrameworkBundle] Add file helper to Controller
dfridrich fb665d2
[FrameworkBundle] Fix coding standard in file helper
dfridrich 2da9399
[FrameworkBundle] Fix coding standard in file helper tests
dfridrich ab19f5a
[FrameworkBundle] Add auto-detect mime type feature in file helper
dfridrich 8dde06e
[FrameworkBundle] Add ability to pass path to file helper
dfridrich 9bbecbc
[FrameworkBundle] Fix typo in file helper
dfridrich 1a58eb9
[FrameworkBundle] Enhance file helper code
dfridrich b647e70
[FrameworkBundle] Enhance file helper code (fix line)
dfridrich 8257508
[FrameworkBundle] Add early return to file helper and make better test.
dfridrich 50264eb
[FrameworkBundle] Fix file helper coding style
dfridrich 86acd27
[FrameworkBundle] Remove file helper code comments.
dfridrich 6fb74b5
[FrameworkBundle] Early exception if file is not readable in file hel…
dfridrich ec0aab9
Remove file from string functionality
dfridrich 26b112c
Remove file from string functionality
dfridrich 921c1f5
Remove unused dead code
dfridrich 3823cfa
Remove file helper throws annotation
dfridrich bc040ac
Add mime type to BinaryFileResponse contructor in file helper
dfridrich 03be5a9
Fix sprint and add test for non existing files
dfridrich 211241d
Remove unnecessary check in file helper
dfridrich 05495e9
Use setContentDisposition method in file helper
dfridrich 3757cb9
Use setContentDisposition method in file helper
dfridrich 63c831d
Simplify file helper
dfridrich cc7315b
Simplify file helper and remove mimetype test for null content-type h…
dfridrich 85dcb96
Use basename function instead of pathinfo
dfridrich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,12 @@ | |
|
||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | ||
use Symfony\Component\DependencyInjection\ContainerAwareTrait; | ||
use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
use Symfony\Component\HttpFoundation\File\File; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\ResponseHeaderBag; | ||
use Symfony\Component\HttpFoundation\StreamedResponse; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
@@ -123,6 +126,23 @@ protected function json($data, $status = 200, $headers = array(), $context = arr | |
return new JsonResponse($data, $status, $headers); | ||
} | ||
|
||
/** | ||
* Returns a BinaryFileResponse object with original or customized file name and disposition header. | ||
* | ||
* @param File|string $file File object or path to file to be sent as response | ||
* @param string|null $fileName File name to be sent to response or null (will use original file name) | ||
* @param string $disposition Disposition of response ("attachment" is default, other type is "inline") | ||
* | ||
* @return BinaryFileResponse | ||
*/ | ||
protected function file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesnt this new method manifest as a BC break when the subclassing controller already contains a |
||
{ | ||
$response = new BinaryFileResponse($file); | ||
$response->setContentDisposition($disposition, $fileName === null ? $response->getFile()->getFileName() : $fileName); | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* Adds a flash message to the current session for type. | ||
* | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
\SplFileInfo|string
to be equal toBinaryFileResponse
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, see #19115