Passed
Pull Request — master (#59)
by Raúl
04:00
created

Httpful::hasParserRegistered()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Httpful;
4
5
class Httpful {
6
    const VERSION = '0.2.20';
7
8
    private static $mimeRegistrar = array();
9
    private static $default = null;
10
11
    /**
12
     * @param string $mimeType
13
     * @param \Httpful\Handlers\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 $mimeType defaults to MimeHandlerAdapter
22
     * @return \Httpful\Handlers\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
     * @param string $mimeType
41
     * @return bool
42
     */
43
    public static function hasParserRegistered($mimeType)
44
    {
45
        return isset(self::$mimeRegistrar[$mimeType]);
46
    }
47
}
48