DownloadController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A gaufretteAction() 0 4 1
A symfonyAction() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the BenGorFile package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorFile\FileBundle\Controller;
14
15
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
17
use Symfony\Component\HttpFoundation\BinaryFileResponse;
18
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
19
20
/**
21
 * File download controller.
22
 *
23
 * @author Beñat Espiña <[email protected]>
24
 */
25
class DownloadController extends Controller
26
{
27
    /**
28
     * Gets the file of given file name in the Gaufrette filesystem.
29
     *
30
     * @param string $filename          The file name
31
     * @param string $uploadDestination The gaufrette filesystem
32
     *
33
     * @return BinaryFileResponse
34
     */
35
    public function gaufretteAction($filename, $uploadDestination)
36
    {
37
        return new BinaryFileResponse('gaufrette://' . $uploadDestination . '/' . $filename);
38
    }
39
40
    /**
41
     * Gets the file of given file name in the Symfony filesystem.
42
     *
43
     * @param string $filename          The file name
44
     * @param string $uploadDestination The path of file storage
45
     *
46
     * @return BinaryFileResponse
47
     */
48
    public function symfonyAction($filename, $uploadDestination)
49
    {
50
        try {
51
            return new BinaryFileResponse($uploadDestination . '/' . $filename);
52
        } catch (FileNotFoundException $exception) {
53
            throw new NotFoundHttpException();
54
        }
55
    }
56
}
57