@@ -52,26 +52,26 @@ discard block |
||
52 | 52 | * Detector constructor. |
53 | 53 | * @param string $pathToData Path to directory with xml data files |
54 | 54 | */ |
55 | - private function __construct($pathToData='auto') |
|
55 | + private function __construct($pathToData = 'auto') |
|
56 | 56 | { |
57 | - if($pathToData == 'auto') |
|
57 | + if ($pathToData == 'auto') |
|
58 | 58 | { |
59 | - $this->setPathToData(str_replace('src','data',__DIR__).'/'); |
|
59 | + $this->setPathToData(str_replace('src', 'data', __DIR__).'/'); |
|
60 | 60 | } |
61 | 61 | |
62 | - $xml = array('robot','browser','device','os'); |
|
62 | + $xml = array('robot', 'browser', 'device', 'os'); |
|
63 | 63 | $xmlData = array(); |
64 | - foreach($xml as $name) |
|
64 | + foreach ($xml as $name) |
|
65 | 65 | { |
66 | 66 | $xmlData[$name] = simplexml_load_file($this->getPathToData().$name.'.xml'); |
67 | 67 | } |
68 | 68 | $this->setXmlData($xmlData); |
69 | 69 | } |
70 | 70 | |
71 | - public static function analyse($uaString='UA', $pathToData='auto') |
|
71 | + public static function analyse($uaString = 'UA', $pathToData = 'auto') |
|
72 | 72 | { |
73 | 73 | $ua = $uaString; |
74 | - if($uaString == 'UA') |
|
74 | + if ($uaString == 'UA') |
|
75 | 75 | { |
76 | 76 | $ua = $_SERVER['HTTP_USER_AGENT']; |
77 | 77 | } |
@@ -79,23 +79,23 @@ discard block |
||
79 | 79 | $detector = new Detector($pathToData); |
80 | 80 | $xml = $detector->getXmlData(); |
81 | 81 | $data = array(); |
82 | - foreach($xml as $key => $item) |
|
82 | + foreach ($xml as $key => $item) |
|
83 | 83 | { |
84 | - $data[$key] = self::analysePart($xml,$key,$ua); |
|
84 | + $data[$key] = self::analysePart($xml, $key, $ua); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | $detectorResult = new DetectorResult(); |
88 | 88 | $detectorResult->uaString = $ua; |
89 | 89 | $isRobot = false; |
90 | 90 | |
91 | - foreach($data as $key => $result) |
|
91 | + foreach ($data as $key => $result) |
|
92 | 92 | { |
93 | - if(!$isRobot) |
|
93 | + if (!$isRobot) |
|
94 | 94 | { |
95 | 95 | switch ($key) |
96 | 96 | { |
97 | 97 | case 'robot': |
98 | - if($result !== null) |
|
98 | + if ($result !== null) |
|
99 | 99 | { |
100 | 100 | $robot = new Robot($result); |
101 | 101 | $detectorResult->Robot = $robot; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | } |
106 | 106 | break; |
107 | 107 | case 'os': |
108 | - if($result !== null) |
|
108 | + if ($result !== null) |
|
109 | 109 | { |
110 | 110 | $os = new OS($result); |
111 | 111 | $os->setVersion(self::getVersion($result, $ua)); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | } |
119 | 119 | break; |
120 | 120 | case 'device': |
121 | - if($result !== null) |
|
121 | + if ($result !== null) |
|
122 | 122 | { |
123 | 123 | $device = new Device($result); |
124 | 124 | $detectorResult->Device = $device; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | } |
131 | 131 | break; |
132 | 132 | case 'browser': |
133 | - if($result !== null) |
|
133 | + if ($result !== null) |
|
134 | 134 | { |
135 | 135 | $browser = new Browser($result); |
136 | 136 | $browser->setVersion(self::getVersion($result, $ua)); |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | * @param string $uaString User agent |
158 | 158 | * @return \SimpleXMLElement xml element |
159 | 159 | */ |
160 | - private static function analysePart($xmlData,$key,$uaString) |
|
160 | + private static function analysePart($xmlData, $key, $uaString) |
|
161 | 161 | { |
162 | 162 | $data = $xmlData[$key]->data; |
163 | - foreach($data as $xmlItem) |
|
163 | + foreach ($data as $xmlItem) |
|
164 | 164 | { |
165 | 165 | $pattern = '/'.$xmlItem->pattern.'/'; |
166 | - if(preg_match($pattern,$uaString)) |
|
166 | + if (preg_match($pattern, $uaString)) |
|
167 | 167 | { |
168 | 168 | return $xmlItem; |
169 | 169 | } |
@@ -176,21 +176,21 @@ discard block |
||
176 | 176 | * @param string $uaString User agent |
177 | 177 | * @return string Version |
178 | 178 | */ |
179 | - private static function getVersion(\SimpleXMLElement $xmlItem,$uaString) |
|
179 | + private static function getVersion(\SimpleXMLElement $xmlItem, $uaString) |
|
180 | 180 | { |
181 | - if($xmlItem !== null) |
|
181 | + if ($xmlItem !== null) |
|
182 | 182 | { |
183 | - foreach($xmlItem->children() as $node) |
|
183 | + foreach ($xmlItem->children() as $node) |
|
184 | 184 | { |
185 | - if($node->getName() == 'versionPattern') |
|
185 | + if ($node->getName() == 'versionPattern') |
|
186 | 186 | { |
187 | 187 | $vPattern = $node->__toString(); |
188 | - $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/'; |
|
188 | + $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
|
189 | 189 | $uaString = str_replace(' NT', '', $uaString); |
190 | 190 | if (preg_match($version, $uaString)) { |
191 | 191 | preg_match($version, $uaString, $v); |
192 | 192 | $version = $v[0]; |
193 | - $version = preg_replace('/' . $vPattern . '/', '', $version); |
|
193 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
194 | 194 | $version = str_replace(';', '', $version); |
195 | 195 | $version = str_replace(' ', '', $version); |
196 | 196 | $version = str_replace('/', '', $version); |
@@ -234,14 +234,14 @@ discard block |
||
234 | 234 | private static function checkRules(DetectorResult $result) |
235 | 235 | { |
236 | 236 | $Rules = DetectorRule::loadRulesFromFile(); |
237 | - foreach($Rules as $rule) |
|
237 | + foreach ($Rules as $rule) |
|
238 | 238 | { |
239 | 239 | $objectType = $rule->getObjectType(); |
240 | 240 | $objectProperty = $rule->getObjectProperty(); |
241 | 241 | $targetType = $rule->getTargetType(); |
242 | 242 | $targetValue = $rule->isTargetValue(); |
243 | 243 | $func = 'get'.$objectProperty; |
244 | - if($result->$objectType !== null) |
|
244 | + if ($result->$objectType !== null) |
|
245 | 245 | { |
246 | 246 | if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) { |
247 | 247 | $result->$targetType = $targetValue; |
@@ -252,4 +252,4 @@ discard block |
||
252 | 252 | return $result; |
253 | 253 | } |
254 | 254 | } |
255 | -define('D_NA','N\A'); |
|
255 | +define('D_NA', 'N\A'); |