PageRenderTime 18ms CodeModel.GetById 11ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_widgetkit/vendor/yootheme/framework/src/View/Asset/Filter/FilterManager.php

https://gitlab.com/vnsoftdev/amms
PHP | 76 lines | 36 code | 13 blank | 27 comment | 2 complexity | dee26d7111986c9aff3cc9701eae4591 MD5 | raw file
 1<?php
 2
 3namespace YOOtheme\Framework\View\Asset\Filter;
 4
 5class FilterManager
 6{
 7    /**
 8     * @var array
 9     */
10    protected $filters = array();
11
12    /**
13     * Constructor.
14     *
15     * @param array $filters
16     */
17    public function __construct(array $filters = array())
18    {
19        foreach ($filters as $name => $filter) {
20            $this->add($name, $filter);
21        }
22    }
23
24    /**
25     * Gets one or multiple filters.
26     *
27     * @param  string|array $name
28     * @return FilterInterface|FilterInterface[]
29     */
30    public function get($name)
31    {
32        if (is_array($name)) {
33
34            $filters = array_flip($name);
35
36            foreach ($filters as $name => $i) {
37                $filters[$name] = $this->filters[$name];
38            }
39
40            return $filters;
41        }
42
43        return isset($this->filters[$name]) ? $this->filters[$name] : null;
44    }
45
46    /**
47     * Adds a named filter.
48     *
49     * @param  string $name
50     * @param  mixed  $filter
51     * @return self
52     */
53    public function add($name, $filter)
54    {
55        if (is_string($filter)) {
56            $filter = new $filter;
57        }
58
59        $this->filters[$name] = $filter;
60
61        return $this;
62    }
63
64    /**
65     * Removes a named filter.
66     *
67     * @param  string $name
68     * @return self
69     */
70    public function remove($name)
71    {
72        unset($this->filters[$name]);
73
74        return $this;
75    }
76}