-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathFilterCollection.php
72 lines (62 loc) · 1.63 KB
/
FilterCollection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php namespace October\Rain\Assetic\Filter;
use October\Rain\Assetic\Asset\AssetInterface;
use Traversable;
/**
* FilterCollection is a collection of filters.
*
* @author Kris Wallsmith <[email protected]>
*/
class FilterCollection implements FilterInterface, \IteratorAggregate, \Countable
{
private $filters = array();
public function __construct($filters = array())
{
foreach ($filters as $filter) {
$this->ensure($filter);
}
}
/**
* Checks that the current collection contains the supplied filter.
*
* If the supplied filter is another filter collection, each of its
* filters will be checked.
*/
public function ensure(FilterInterface $filter)
{
if ($filter instanceof \Traversable) {
foreach ($filter as $f) {
$this->ensure($f);
}
} elseif (!in_array($filter, $this->filters, true)) {
$this->filters[] = $filter;
}
}
public function all()
{
return $this->filters;
}
public function clear()
{
$this->filters = array();
}
public function filterLoad(AssetInterface $asset)
{
foreach ($this->filters as $filter) {
$filter->filterLoad($asset);
}
}
public function filterDump(AssetInterface $asset)
{
foreach ($this->filters as $filter) {
$filter->filterDump($asset);
}
}
public function getIterator(): Traversable
{
return new \ArrayIterator($this->filters);
}
public function count(): int
{
return count($this->filters);
}
}