blob: defff4363a3ba2c2d4d608e250d5a66b50ead276 (
plain)
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
|
<?php
namespace ipl\Stdlib;
trait Filters
{
/** @var Filter\Chain */
protected $filter;
public function getFilter()
{
return $this->filter ?: Filter::all();
}
public function filter(Filter\Rule $filter)
{
$currentFilter = $this->getFilter();
if ($currentFilter instanceof Filter\All) {
$this->filter = $currentFilter->add($filter);
} else {
$this->filter = Filter::all($filter);
if (! $currentFilter->isEmpty()) {
$this->filter->insertBefore($currentFilter, $filter);
}
}
return $this;
}
public function orFilter(Filter\Rule $filter)
{
$currentFilter = $this->getFilter();
if ($currentFilter instanceof Filter\Any) {
$this->filter = $currentFilter->add($filter);
} else {
$this->filter = Filter::any($filter);
if (! $currentFilter->isEmpty()) {
$this->filter->insertBefore($currentFilter, $filter);
}
}
return $this;
}
public function notFilter(Filter\Rule $filter)
{
$this->filter(Filter::none($filter));
return $this;
}
public function orNotFilter(Filter\Rule $filter)
{
$this->orFilter(Filter::none($filter));
return $this;
}
}
|