Passed
Pull Request — master (#120)
by Ralf
10:08
created

Httpful   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5
1
<?php
2
3
namespace Httpful;
4
5
class Httpful {
6
    const VERSION = '0.2.18';
7
8
    private static $mimeRegistrar = array();
9
    private static $default = null;
10
11
    /**
12
     * @param string $mime_type
13
     * @param MimeHandlerAdapter $handler
14
     */
15
    public static function register($mimeType, \Httpful\Handlers\MimeHandlerAdapter $handler)
16
    {
17
        self::$mimeRegistrar[$mimeType] = $handler;
18
    }
19
20
    /**
21
     * @param string $mime_type defaults to MimeHandlerAdapter
22
     * @return MimeHandlerAdapter
23
     */
24
    public static function get($mimeType = null)
25
    {
26
        if (isset(self::$mimeRegistrar[$mimeType])) {
27
            return self::$mimeRegistrar[$mimeType];
28
        }
29
30
        if (empty(self::$default)) {
31
            self::$default = new \Httpful\Handlers\MimeHandlerAdapter();
32
        }
33
34
        return self::$default;
35
    }
36
37
    /**
38
     * Does this particular Mime Type have a parser registered
39
     * for it?
40
     * @return bool
41
     */
42
    public static function hasParserRegistered($mimeType)
43
    {
44
        return isset(self::$mimeRegistrar[$mimeType]);
45
    }
46
}
47