Skip to content
Snippets Groups Projects

[#3499849] Simplify class overrides

2 files
+ 34
209
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -76,42 +76,23 @@ class XsendfileFileDownloadController extends FileDownloadController {
@@ -76,42 +76,23 @@ class XsendfileFileDownloadController extends FileDownloadController {
* @see hook_file_download()
* @see hook_file_download()
*/
*/
public function download(Request $request, $scheme = 'private') {
public function download(Request $request, $scheme = 'private') {
$target = $request->query->get('file');
$response = parent::download($request, $scheme);
// Merge remaining path arguments into relative file path.
if (!$response instanceof BinaryFileResponse) {
$uri = $this->streamWrapperManager->normalizeUri($scheme . '://' . $target);
return $response;
}
if ($this->streamWrapperManager->isValidScheme($scheme) && is_file($uri)) {
// Let other modules provide headers and controls access to the file.
$headers = $this->moduleHandler()->invokeAll('file_download', [$uri]);
foreach ($headers as $result) {
if ($result == -1) {
throw new AccessDeniedHttpException();
}
}
if (count($headers)) {
$download_method = $this->config('xsendfile.settings')->get('xsendfile_transfer');
if ($download_method == $this->fileDownloadHeaders::XSENDFILE_PHP_TRANSFER) {
// \Drupal\Core\EventSubscriber\FinishResponseSubscriber::onRespond()
// sets response as not cacheable if the Cache-Control header is not
// already modified. We pass in FALSE for non-private schemes for the
// $public parameter to make sure we don't change the headers.
return new BinaryFileResponse($uri, 200, $headers, $scheme !== 'private');
}
else {
$file_path = base_path() . Settings::get('file_private_path') . '/' . $target;
$xsendfile_headers = $this->fileDownloadHeaders->getHeaders($file_path);
$headers += $xsendfile_headers;
return new Response('', 200, $headers);
}
}
throw new AccessDeniedHttpException();
$download_method = $this->config('xsendfile.settings')->get('xsendfile_transfer');
 
if ($download_method == $this->fileDownloadHeaders::XSENDFILE_PHP_TRANSFER) {
 
return $response;
}
}
throw new NotFoundHttpException();
$target = $request->query->get('file');
 
$file_path = base_path() . Settings::get('file_private_path') . '/' . $target;
 
$xsendfile_headers = $this->fileDownloadHeaders->getHeaders($file_path);
 
$headers = $response->headers->all();
 
$headers += $xsendfile_headers;
 
 
return new Response('', 200, $headers);
}
}
}
}
Loading