Completed
Push — master ( 08cbf3...6ef5d2 )
by Cheren
04:26
created

FilterManager::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
/**
3
 * JBZoo Assets
4
 *
5
 * This file is part of the JBZoo CCK package.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package   Assets
10
 * @license   MIT
11
 * @copyright Copyright (C) JBZoo.com,  All rights reserved.
12
 * @link      https://github.com/JBZoo/Assets
13
 * @author    Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace JBZoo\Assets\Filter;
17
18
use JBZoo\Data\Data;
19
use JBZoo\Utils\Arr;
20
21
/**
22
 * Class FilterManager
23
 *
24
 * @package JBZoo\Assets\Filter
25
 */
26
class FilterManager
27
{
28
29
    /**
30
     * Filter map.
31
     *
32
     * @var array
33
     */
34
    protected $_filters = [
35
        'CssCompressor' => 'JBZoo\Assets\Filter\CssCompressor',
36
    ];
37
38
    /**
39
     * Get filter by name.
40
     *
41
     * @param $name
42
     * @return bool|FilterAbstract
43
     */
44
    public function get($name)
45
    {
46
        if (Arr::key($name, $this->_filters)) {
47
            return new $this->_filters[$name]();
48
        }
49
50
        return false;
51
    }
52
53
    /**
54
     * Add new filter.
55
     *
56
     * @param string $name
57
     * @param string $class
58
     * @return $this
59
     */
60
    public function add($name, $class)
61
    {
62
        $this->_filters[$name] = $class;
63
        return $this;
64
    }
65
}
66