1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace smtech\CanvasICSSync\SyncIntoCanvas; |
4
|
|
|
|
5
|
|
|
class Filter |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Whether or not this filter is enabled |
9
|
|
|
* @var boolean |
10
|
|
|
*/ |
11
|
|
|
protected $enabled = false; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Regex to include (applied first) |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $include; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Regex to exclude (applied second) |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $exclude; |
24
|
|
|
|
25
|
|
|
public function __construct($enabled, $include, $exclude) |
26
|
|
|
{ |
27
|
|
|
$this->setEnabled($enabled); |
28
|
|
|
$this->setIncludeExpression($include); |
29
|
|
|
$this->setExcludeExpression($exclude); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function setEnabled($enabled) |
33
|
|
|
{ |
34
|
|
|
$this->enabled = (boolean) $enabled; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function isEnabled() |
38
|
|
|
{ |
39
|
|
|
return $enabled; |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function setIncludeExpression($regex) |
43
|
|
|
{ |
44
|
|
|
$this->include = (string) $regex; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getIncludeExpression() |
48
|
|
|
{ |
49
|
|
|
if (empty($this->include)) { |
50
|
|
|
return false; |
51
|
|
|
} |
52
|
|
|
return $this->include; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setExcludeExpression($regex) |
56
|
|
|
{ |
57
|
|
|
$this->exclude = (string) $regex; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getExcludeExpression() |
61
|
|
|
{ |
62
|
|
|
if (empty($this->exclude)) { |
63
|
|
|
return false; |
64
|
|
|
} |
65
|
|
|
return $this->exclude; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function filter(Event $event) |
69
|
|
|
{ |
70
|
|
|
return ( |
71
|
|
|
// include this event if filtering is off... |
72
|
|
|
$this->isEnabled() == false || |
73
|
|
|
( |
74
|
|
|
( |
75
|
|
|
( // if filtering is on, and there's an include pattern test that pattern... |
76
|
|
|
$this->getIncludeExpression() && |
|
|
|
|
77
|
|
|
preg_match('%' . $this->getIncludeExpression() . '%', $event->getProperty('SUMMARY')) |
|
|
|
|
78
|
|
|
) |
79
|
|
|
) && |
80
|
|
|
!( // if there is an exclude pattern, make sure that this event is NOT excluded |
81
|
|
|
$this->getExcludeExpression() && |
|
|
|
|
82
|
|
|
preg_match('%' . $this->getExcludeExpression() . '%', $event->getProperty('SUMMARY')) |
|
|
|
|
83
|
|
|
) |
84
|
|
|
) |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.