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) { |
|
|
|
|
51
|
|
|
throw new FileDownloadFaildException($e->getMessage(), NULL, $e); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
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.