Completed
Push — master ( 2ede7a...256325 )
by Benjamin
04:30
created

MediaExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 4
dl 0
loc 38
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 4 1
A getFunctions() 0 6 1
A getFilters() 0 6 1
A generateMediaUrl() 0 4 1
A getAllowedMimeTypes() 0 4 1
1
<?php
2
3
namespace Alpixel\Bundle\MediaBundle\Twig\Extension;
4
5
use Alpixel\Bundle\MediaBundle\Entity\Media;
6
use Alpixel\Bundle\MediaBundle\Services\MediaManager;
7
8
class MediaExtension extends \Twig_Extension
9
{
10
    protected $mediaManager;
11
12
    public function __construct(MediaManager $mm)
13
    {
14
        $this->mediaManager = $mm;
15
    }
16
17
    public function getName()
18
    {
19
        return 'alpixel_media';
20
    }
21
22
    public function getFunctions()
23
    {
24
        return [
25
            new \Twig_SimpleFunction('alpixel_media_allowed_mimetypes', [$this, 'getAllowedMimeTypes']),
26
        ];
27
    }
28
29
    public function getFilters()
30
    {
31
        return [
32
            new \Twig_SimpleFilter('media_url', [$this, 'generateMediaUrl']),
33
        ];
34
    }
35
36
    public function generateMediaUrl(Media $media, $options = [])
37
    {
38
        return $this->mediaManager->generateUrl($media, $options);
39
    }
40
41
    public function getAllowedMimeTypes()
42
    {
43
        return $this->mediaManager->getAllowedMimeTypes();
44
    }
45
}
46