Completed
Push — master ( f74467...66dab2 )
by
unknown
07:31
created

MediaController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 40
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0

3 Methods

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