Completed
Push — master ( 331ac1...00209f )
by Milan
02:04
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 string $alias
29
	 * @return self
30
	 */
31
	public function setDestination($alias)
32
	{
33
		$this->documentRoot->setDestination($alias);
34
		return $this;
35
	}
36
37
	/**
38
	 * @param IStoreFile $file
39
	 * @param bool $forceDownload
40
	 * @return Application\Responses\FileResponse
41
	 */
42
	public function create(IStoreFile $file, $forceDownload = TRUE)
43
	{
44
		return new Application\Responses\FileResponse($this->documentRoot->createAbsolutePath($file), $file->getName(), $file->getContentType(), $forceDownload);
45
	}
46
47
	/**
48
	 * @param IStoreFile $file
49
	 * @param bool $forceDownload
50
	 * @throws FileDownloadFaildException
51
	 */
52
	public function send(IStoreFile $file, $forceDownload = TRUE)
53
	{
54
		try {
55
			$this->create($file, $forceDownload)->send($this->request, $this->response);
56
		} 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...
57
			throw new FileDownloadFaildException($e->getMessage(), NULL, $e);
58
		}
59
	}
60
61
}
62