1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Sergey Nehaenko <[email protected]> |
4
|
|
|
* @license GPL |
5
|
|
|
* @copyright Sergey Nehaenko © 2016 |
6
|
|
|
* @version 3.0.0 |
7
|
|
|
* @project browser-detector |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace EndorphinStudio\Detector; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class DetectorRule |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @return string |
17
|
|
|
*/ |
18
|
|
|
public function getObjectType() |
19
|
|
|
{ |
20
|
|
|
return $this->ObjectType; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return string |
25
|
|
|
*/ |
26
|
|
|
public function getObjectProperty() |
27
|
|
|
{ |
28
|
|
|
return $this->ObjectProperty; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
public function getObjectPropertyValue() |
35
|
|
|
{ |
36
|
|
|
return $this->ObjectPropertyValue; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public function getTargetType() |
43
|
|
|
{ |
44
|
|
|
return $this->TargetType; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return boolean |
49
|
|
|
*/ |
50
|
|
|
public function isTargetValue() |
51
|
|
|
{ |
52
|
|
|
return $this->TargetValue; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $ObjectType |
57
|
|
|
*/ |
58
|
|
|
public function setObjectType($ObjectType) |
59
|
|
|
{ |
60
|
|
|
$this->ObjectType = $ObjectType; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param boolean $TargetValue |
65
|
|
|
*/ |
66
|
|
|
public function setTargetValue($TargetValue) |
67
|
|
|
{ |
68
|
|
|
$this->TargetValue = $TargetValue; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string $TargetType |
73
|
|
|
*/ |
74
|
|
|
public function setTargetType($TargetType) |
75
|
|
|
{ |
76
|
|
|
$this->TargetType = $TargetType; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $ObjectPropertyValue |
81
|
|
|
*/ |
82
|
|
|
public function setObjectPropertyValue($ObjectPropertyValue) |
83
|
|
|
{ |
84
|
|
|
$this->ObjectPropertyValue = $ObjectPropertyValue; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string $ObjectProperty |
89
|
|
|
*/ |
90
|
|
|
public function setObjectProperty($ObjectProperty) |
91
|
|
|
{ |
92
|
|
|
$this->ObjectProperty = $ObjectProperty; |
93
|
|
|
} |
94
|
|
|
/** @var string EndorphinStudio\Detector\DetectorResult object name */ |
95
|
|
|
private $ObjectType; |
96
|
|
|
/** @var string EndorphinStudio\Detector\DetectorResult property name */ |
97
|
|
|
private $ObjectProperty; |
98
|
|
|
/** @var string EndorphinStudio\Detector\DetectorResult property value */ |
99
|
|
|
private $ObjectPropertyValue; |
100
|
|
|
/** @var string EndorphinStudio\Detector\DetectorResult property name */ |
101
|
|
|
private $TargetType; |
102
|
|
|
/** @var boolean boolean value */ |
103
|
|
|
private $TargetValue; |
104
|
|
|
|
105
|
|
|
public function __construct(\SimpleXMLElement $xmlData) |
106
|
|
|
{ |
107
|
|
|
if($xmlData !== null) |
108
|
|
|
{ |
109
|
|
|
foreach ($xmlData->children() as $child) |
110
|
|
|
{ |
111
|
|
|
$name = $child->getName(); |
112
|
|
|
$val = $child->__toString(); |
113
|
|
|
if($name != 'TargetValue') |
114
|
|
|
{ |
115
|
|
|
$this->$name = $val; |
116
|
|
|
} |
117
|
|
|
else |
118
|
|
|
$this->$name = filter_var($val, FILTER_VALIDATE_BOOLEAN); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return array Array of EndorphinStudio\Detector\DetectorRule objects |
125
|
|
|
*/ |
126
|
|
|
public static function loadRulesFromFile() |
127
|
|
|
{ |
128
|
|
|
$path = str_replace('src','data',__DIR__).'/rules/'; |
129
|
|
|
$files = scandir($path); |
130
|
|
|
$rules = array(); |
131
|
|
|
foreach($files as $file) |
132
|
|
|
{ |
133
|
|
|
if($file != '.' && $file != '..') |
134
|
|
|
{ |
135
|
|
|
$xmlObj = simplexml_load_file($path.$file); |
136
|
|
|
foreach($xmlObj->children() as $rule) |
137
|
|
|
{ |
138
|
|
|
$rules[] = new self($rule); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $rules; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|