Passed
Push — master ( 80661e...c8031b )
by Milan
02:11
created

src/Download.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace h4kuna\Upload;
4
5
use Nette\Application;
6
use Nette\Http;
7
8
class Download
9
{
10
11
	/** @var IDriver */
12
	private $driver;
13
14
	/** @var Http\Request */
15
	private $request;
16
17
	/** @var Http\Response */
18
	private $response;
19
20
21
	public function __construct(IDriver $driver, Http\Request $request, Http\Response $response)
22
	{
23
		$this->driver = $driver;
24
		$this->request = $request;
25
		$this->response = $response;
26
	}
27
28
29
	/**
30
	 * @param IStoreFile $file
31
	 * @param bool $forceDownload
32
	 * @return Application\Responses\FileResponse
33
	 */
34
	public function createFileResponse(IStoreFile $file, $forceDownload = true)
35
	{
36
		return new Application\Responses\FileResponse(
37
			$this->driver->createURI($file),
38
			$file->getName(), $file->getContentType(), $forceDownload);
39
	}
40
41
42
	/**
43
	 * @param IStoreFile $file
44
	 * @param bool $forceDownload
45
	 * @throws FileDownloadFailedException
46
	 */
47
	public function send(IStoreFile $file, $forceDownload = true)
48
	{
49
		try {
50
			$this->createFileResponse($file, $forceDownload)->send($this->request, $this->response);
51
		} catch (Application\BadRequestException $e) {
0 ignored issues
show
The class Nette\Application\BadRequestException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
52
			throw new FileDownloadFailedException($e->getMessage(), null, $e);
53
		}
54
	}
55
}
56