Skip to content

Commit 04f08d8

Browse files
authored
Fix deprecation notice (#131)
1 parent dd05564 commit 04f08d8

File tree

1 file changed

+82
-68
lines changed

1 file changed

+82
-68
lines changed

src/Web/WebClient.php

Lines changed: 82 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -280,72 +280,74 @@ public function __get($name)
280280
*/
281281
protected function detectBrowser($userAgent)
282282
{
283-
if (!empty($userAgent)) {
284-
$patternBrowser = '';
285-
286-
// Attempt to detect the browser type. Obviously we are only worried about major browsers.
287-
if ((\stripos($userAgent, 'MSIE') !== false) && (\stripos($userAgent, 'Opera') === false)) {
288-
$this->browser = self::IE;
289-
$patternBrowser = 'MSIE';
290-
} elseif (\stripos($userAgent, 'Trident') !== false) {
291-
$this->browser = self::IE;
292-
$patternBrowser = ' rv';
293-
} elseif (\stripos($userAgent, 'Edge') !== false) {
294-
$this->browser = self::EDGE;
295-
$patternBrowser = 'Edge';
296-
} elseif (\stripos($userAgent, 'Edg') !== false) {
297-
$this->browser = self::EDG;
298-
$patternBrowser = 'Edg';
299-
} elseif ((\stripos($userAgent, 'Firefox') !== false) && (\stripos($userAgent, 'like Firefox') === false)) {
300-
$this->browser = self::FIREFOX;
301-
$patternBrowser = 'Firefox';
302-
} elseif (\stripos($userAgent, 'OPR') !== false) {
303-
$this->browser = self::OPERA;
304-
$patternBrowser = 'OPR';
305-
} elseif (\stripos($userAgent, 'Chrome') !== false) {
306-
$this->browser = self::CHROME;
307-
$patternBrowser = 'Chrome';
308-
} elseif (\stripos($userAgent, 'Safari') !== false) {
309-
$this->browser = self::SAFARI;
310-
$patternBrowser = 'Safari';
311-
} elseif (\stripos($userAgent, 'Opera') !== false) {
312-
$this->browser = self::OPERA;
313-
$patternBrowser = 'Opera';
314-
}
283+
// Mark this detection routine as run.
284+
$this->detection['browser'] = true;
315285

316-
// If we detected a known browser let's attempt to determine the version.
317-
if ($this->browser) {
318-
// Build the REGEX pattern to match the browser version string within the user agent string.
319-
$pattern = '#(?<browser>Version|' . $patternBrowser . ')[/ :]+(?<version>[0-9.|a-zA-Z.]*)#';
320-
321-
// Attempt to find version strings in the user agent string.
322-
$matches = [];
323-
324-
if (\preg_match_all($pattern, $userAgent, $matches)) {
325-
// Do we have both a Version and browser match?
326-
if (\count($matches['browser']) == 2) {
327-
// See whether Version or browser came first, and use the number accordingly.
328-
if (\strripos($userAgent, 'Version') < \strripos($userAgent, $patternBrowser)) {
329-
$this->browserVersion = $matches['version'][0];
330-
} else {
331-
$this->browserVersion = $matches['version'][1];
332-
}
333-
} elseif (\count($matches['browser']) > 2) {
334-
$key = \array_search('Version', $matches['browser']);
335-
336-
if ($key) {
337-
$this->browserVersion = $matches['version'][$key];
338-
}
339-
} else {
340-
// We only have a Version or a browser so use what we have.
286+
if (empty($userAgent)) {
287+
return;
288+
}
289+
290+
$patternBrowser = '';
291+
292+
// Attempt to detect the browser type. Obviously we are only worried about major browsers.
293+
if ((\stripos($userAgent, 'MSIE') !== false) && (\stripos($userAgent, 'Opera') === false)) {
294+
$this->browser = self::IE;
295+
$patternBrowser = 'MSIE';
296+
} elseif (\stripos($userAgent, 'Trident') !== false) {
297+
$this->browser = self::IE;
298+
$patternBrowser = ' rv';
299+
} elseif (\stripos($userAgent, 'Edge') !== false) {
300+
$this->browser = self::EDGE;
301+
$patternBrowser = 'Edge';
302+
} elseif (\stripos($userAgent, 'Edg') !== false) {
303+
$this->browser = self::EDG;
304+
$patternBrowser = 'Edg';
305+
} elseif ((\stripos($userAgent, 'Firefox') !== false) && (\stripos($userAgent, 'like Firefox') === false)) {
306+
$this->browser = self::FIREFOX;
307+
$patternBrowser = 'Firefox';
308+
} elseif (\stripos($userAgent, 'OPR') !== false) {
309+
$this->browser = self::OPERA;
310+
$patternBrowser = 'OPR';
311+
} elseif (\stripos($userAgent, 'Chrome') !== false) {
312+
$this->browser = self::CHROME;
313+
$patternBrowser = 'Chrome';
314+
} elseif (\stripos($userAgent, 'Safari') !== false) {
315+
$this->browser = self::SAFARI;
316+
$patternBrowser = 'Safari';
317+
} elseif (\stripos($userAgent, 'Opera') !== false) {
318+
$this->browser = self::OPERA;
319+
$patternBrowser = 'Opera';
320+
}
321+
322+
// If we detected a known browser let's attempt to determine the version.
323+
if ($this->browser) {
324+
// Build the REGEX pattern to match the browser version string within the user agent string.
325+
$pattern = '#(?<browser>Version|' . $patternBrowser . ')[/ :]+(?<version>[0-9.|a-zA-Z.]*)#';
326+
327+
// Attempt to find version strings in the user agent string.
328+
$matches = [];
329+
330+
if (\preg_match_all($pattern, $userAgent, $matches)) {
331+
// Do we have both a Version and browser match?
332+
if (\count($matches['browser']) == 2) {
333+
// See whether Version or browser came first, and use the number accordingly.
334+
if (\strripos($userAgent, 'Version') < \strripos($userAgent, $patternBrowser)) {
341335
$this->browserVersion = $matches['version'][0];
336+
} else {
337+
$this->browserVersion = $matches['version'][1];
338+
}
339+
} elseif (\count($matches['browser']) > 2) {
340+
$key = \array_search('Version', $matches['browser']);
341+
342+
if ($key) {
343+
$this->browserVersion = $matches['version'][$key];
342344
}
345+
} else {
346+
// We only have a Version or a browser so use what we have.
347+
$this->browserVersion = $matches['version'][0];
343348
}
344349
}
345350
}
346-
347-
// Mark this detection routine as run.
348-
$this->detection['browser'] = true;
349351
}
350352

351353
/**
@@ -377,6 +379,13 @@ protected function detectEncoding($acceptEncoding)
377379
*/
378380
protected function detectEngine($userAgent)
379381
{
382+
// Mark this detection routine as run.
383+
$this->detection['engine'] = true;
384+
385+
if (empty($userAgent)) {
386+
return;
387+
}
388+
380389
if (\stripos($userAgent, 'MSIE') !== false || \stripos($userAgent, 'Trident') !== false) {
381390
// Attempt to detect the client engine -- starting with the most popular ... for now.
382391
$this->engine = self::TRIDENT;
@@ -434,9 +443,6 @@ protected function detectEngine($userAgent)
434443
// Lesser known engine but it finishes off the major list from Wikipedia :-)
435444
$this->engine = self::AMAYA;
436445
}
437-
438-
// Mark this detection routine as run.
439-
$this->detection['engine'] = true;
440446
}
441447

442448
/**
@@ -468,6 +474,13 @@ protected function detectLanguage($acceptLanguage)
468474
*/
469475
protected function detectPlatform($userAgent)
470476
{
477+
// Mark this detection routine as run.
478+
$this->detection['platform'] = true;
479+
480+
if (empty($userAgent)) {
481+
return;
482+
}
483+
471484
// Attempt to detect the client platform.
472485
if (\stripos($userAgent, 'Windows') !== false) {
473486
$this->platform = self::WINDOWS;
@@ -526,9 +539,6 @@ protected function detectPlatform($userAgent)
526539
} elseif (\stripos($userAgent, 'Linux') !== false) {
527540
$this->platform = self::LINUX;
528541
}
529-
530-
// Mark this detection routine as run.
531-
$this->detection['platform'] = true;
532542
}
533543

534544
/**
@@ -542,9 +552,13 @@ protected function detectPlatform($userAgent)
542552
*/
543553
protected function detectRobot($userAgent)
544554
{
545-
$this->robot = (bool) \preg_match('/http|bot|robot|spider|crawler|curl|^$/i', $userAgent);
546-
547555
$this->detection['robot'] = true;
556+
557+
if (empty($userAgent)) {
558+
return;
559+
}
560+
561+
$this->robot = (bool) \preg_match('/http|bot|robot|spider|crawler|curl|^$/i', $userAgent);
548562
}
549563

550564
/**

0 commit comments

Comments
 (0)