Completed
Push — master ( c383ac...a7fbb8 )
by Milan
01:52 queued 01:52
created

FileResponseFactory::setDestination()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace h4kuna\Upload;
4
5
use Nette\Application,
6
	Nette\Http;
7
8
class FileResponseFactory
9
{
10
11
	/** @var Http\Request */
12
	private $request;
13
14
	/** @var Http\Response */
15
	private $response;
16
17
	/** @var DocumentRoot */
18
	private $documentRoot;
19
20
	public function __construct(Http\Request $request, Http\Response $response, DocumentRoot $documentRoot)
21
	{
22
		$this->request = $request;
23
		$this->response = $response;
24
		$this->documentRoot = $documentRoot;
25
	}
26
27
	/**
28
	 * @param IStoreFile $file
29
	 * @param bool $forceDownload
30
	 * @param string|NULL $destinationAlias
31
	 * @return Application\Responses\FileResponse
32
	 */
33
	public function create(IStoreFile $file, $forceDownload = TRUE, $destinationAlias = NULL)
34
	{
35
		return new Application\Responses\FileResponse(
36
			$this->documentRoot->createAbsolutePath($file, $destinationAlias),
37
			$file->getName(), $file->getContentType(), $forceDownload);
38
	}
39
40
	/**
41
	 * @param IStoreFile $file
42
	 * @param bool $forceDownload
43
	 * @param string|NULL $destinationAlias
44
	 * @throws FileDownloadFaildException
45
	 */
46
	public function send(IStoreFile $file, $forceDownload = TRUE, $destinationAlias = NULL)
47
	{
48
		try {
49
			$this->create($file, $forceDownload, $destinationAlias)->send($this->request, $this->response);
50
		} catch (Application\BadRequestException $e) {
0 ignored issues
show
Bug introduced by
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...
51
			throw new FileDownloadFaildException($e->getMessage(), NULL, $e);
52
		}
53
	}
54
55
}
56