Completed
Push — master ( c8a99f...96e898 )
by David
03:18
created

CustomMimetypeHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addMimetype() 0 6 1
A getMimetypeFromExtension() 0 8 2
1
<?php
2
3
namespace Http\Message\MultipartStream;
4
5
/**
6
 * Let you add your own mimetypes. The mimetype lookup will fallback on the ApacheMimeTypeHelper.
7
 *
8
 * @author Tobias Nyholm <[email protected]>
9
 */
10
class CustomMimetypeHelper extends ApacheMimetypeHelper
11
{
12
    /**
13
     * @var array
14
     */
15
    private $mimetypes = [];
16
17
    /**
18
     * @param array $mimetypes should be of type extension => mimetype
19
     */
20
    public function __construct(array $mimetypes = [])
21
    {
22
        $this->mimetypes = $mimetypes;
23
    }
24
25
    /**
26
     * @param string $extension
27
     * @param string $mimetype
28
     *
29
     * @return $this
30
     */
31
    public function addMimetype($extension, $mimetype)
32
    {
33
        $this->mimetypes[$extension] = $mimetype;
34
35
        return $this;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * Check if we have any defined mimetypes and of not fallback to ApacheMimetypeHelper
42
     */
43
    public function getMimetypeFromExtension($extension)
44
    {
45
        $extension = strtolower($extension);
46
47
        return isset($this->mimetypes[$extension])
48
            ? $this->mimetypes[$extension]
49
            : parent::getMimetypeFromExtension($extension);
50
    }
51
}
52