Completed
Push — master ( c28f31...fd8346 )
by
unknown
09:46
created

MediaController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 42
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A imageRedirectAction() 0 7 1
A downloadAction() 0 7 1
A getMediaById() 0 7 1
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\Controller;
4
5
use MediaMonks\SonataMediaBundle\ParameterBag\DownloadParameterBag;
6
use MediaMonks\SonataMediaBundle\ParameterBag\ImageParameterBag;
7
use MediaMonks\SonataMediaBundle\Model\MediaInterface;
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\StreamedResponse;
12
13
class MediaController extends Controller
14
{
15
    /**
16
     * @param Request $request
17
     * @param int $id
18
     * @param int $width
19
     * @param int $height
20
     * @return RedirectResponse
21
     */
22
    public function imageRedirectAction(Request $request, $id, $width, $height)
23
    {
24
        return $this->get('mediamonks.sonata_media.utility.image')->getRedirectResponse(
25
            $this->getMediaById($id),
26
            new ImageParameterBag($width, $height, $request->query->all())
27
        );
28
    }
29
30
    /**
31
     * @param Request $request
32
     * @param $id
33
     * @return StreamedResponse
34
     */
35
    public function downloadAction(Request $request, $id)
36
    {
37
        return $this->get('mediamonks.sonata_media.utility.download')->getStreamedResponse(
38
            $this->getMediaById($id),
39
            new DownloadParameterBag($request->query->all())
40
        );
41
    }
42
43
    /**
44
     * @param $id
45
     * @return MediaInterface
46
     */
47
    protected function getMediaById($id)
48
    {
49
        return $this->getDoctrine()->getManager()->find(
50
            $this->getParameter('mediamonks.sonata_media.entity.class'),
51
            $id
52
        );
53
    }
54
}
55