Skip to content

Commit

Permalink
fix php 8.1 deprecation in WebClient (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
alikon authored Jan 18, 2024
1 parent 96d279d commit 608393d
Showing 1 changed file with 57 additions and 55 deletions.
112 changes: 57 additions & 55 deletions src/Web/WebClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,64 +280,66 @@ public function __get($name)
*/
protected function detectBrowser($userAgent)
{
$patternBrowser = '';

// Attempt to detect the browser type. Obviously we are only worried about major browsers.
if ((\stripos($userAgent, 'MSIE') !== false) && (\stripos($userAgent, 'Opera') === false)) {
$this->browser = self::IE;
$patternBrowser = 'MSIE';
} elseif (\stripos($userAgent, 'Trident') !== false) {
$this->browser = self::IE;
$patternBrowser = ' rv';
} elseif (\stripos($userAgent, 'Edge') !== false) {
$this->browser = self::EDGE;
$patternBrowser = 'Edge';
} elseif (\stripos($userAgent, 'Edg') !== false) {
$this->browser = self::EDG;
$patternBrowser = 'Edg';
} elseif ((\stripos($userAgent, 'Firefox') !== false) && (\stripos($userAgent, 'like Firefox') === false)) {
$this->browser = self::FIREFOX;
$patternBrowser = 'Firefox';
} elseif (\stripos($userAgent, 'OPR') !== false) {
$this->browser = self::OPERA;
$patternBrowser = 'OPR';
} elseif (\stripos($userAgent, 'Chrome') !== false) {
$this->browser = self::CHROME;
$patternBrowser = 'Chrome';
} elseif (\stripos($userAgent, 'Safari') !== false) {
$this->browser = self::SAFARI;
$patternBrowser = 'Safari';
} elseif (\stripos($userAgent, 'Opera') !== false) {
$this->browser = self::OPERA;
$patternBrowser = 'Opera';
}

// If we detected a known browser let's attempt to determine the version.
if ($this->browser) {
// Build the REGEX pattern to match the browser version string within the user agent string.
$pattern = '#(?<browser>Version|' . $patternBrowser . ')[/ :]+(?<version>[0-9.|a-zA-Z.]*)#';

// Attempt to find version strings in the user agent string.
$matches = [];
if (!empty($userAgent)) {
$patternBrowser = '';

// Attempt to detect the browser type. Obviously we are only worried about major browsers.
if ((\stripos($userAgent, 'MSIE') !== false) && (\stripos($userAgent, 'Opera') === false)) {
$this->browser = self::IE;
$patternBrowser = 'MSIE';
} elseif (\stripos($userAgent, 'Trident') !== false) {
$this->browser = self::IE;
$patternBrowser = ' rv';
} elseif (\stripos($userAgent, 'Edge') !== false) {
$this->browser = self::EDGE;
$patternBrowser = 'Edge';
} elseif (\stripos($userAgent, 'Edg') !== false) {
$this->browser = self::EDG;
$patternBrowser = 'Edg';
} elseif ((\stripos($userAgent, 'Firefox') !== false) && (\stripos($userAgent, 'like Firefox') === false)) {
$this->browser = self::FIREFOX;
$patternBrowser = 'Firefox';
} elseif (\stripos($userAgent, 'OPR') !== false) {
$this->browser = self::OPERA;
$patternBrowser = 'OPR';
} elseif (\stripos($userAgent, 'Chrome') !== false) {
$this->browser = self::CHROME;
$patternBrowser = 'Chrome';
} elseif (\stripos($userAgent, 'Safari') !== false) {
$this->browser = self::SAFARI;
$patternBrowser = 'Safari';
} elseif (\stripos($userAgent, 'Opera') !== false) {
$this->browser = self::OPERA;
$patternBrowser = 'Opera';
}

if (\preg_match_all($pattern, $userAgent, $matches)) {
// Do we have both a Version and browser match?
if (\count($matches['browser']) == 2) {
// See whether Version or browser came first, and use the number accordingly.
if (\strripos($userAgent, 'Version') < \strripos($userAgent, $patternBrowser)) {
$this->browserVersion = $matches['version'][0];
// If we detected a known browser let's attempt to determine the version.
if ($this->browser) {
// Build the REGEX pattern to match the browser version string within the user agent string.
$pattern = '#(?<browser>Version|' . $patternBrowser . ')[/ :]+(?<version>[0-9.|a-zA-Z.]*)#';

// Attempt to find version strings in the user agent string.
$matches = [];

if (\preg_match_all($pattern, $userAgent, $matches)) {
// Do we have both a Version and browser match?
if (\count($matches['browser']) == 2) {
// See whether Version or browser came first, and use the number accordingly.
if (\strripos($userAgent, 'Version') < \strripos($userAgent, $patternBrowser)) {
$this->browserVersion = $matches['version'][0];
} else {
$this->browserVersion = $matches['version'][1];
}
} elseif (\count($matches['browser']) > 2) {
$key = \array_search('Version', $matches['browser']);

if ($key) {
$this->browserVersion = $matches['version'][$key];
}
} else {
$this->browserVersion = $matches['version'][1];
}
} elseif (\count($matches['browser']) > 2) {
$key = \array_search('Version', $matches['browser']);

if ($key) {
$this->browserVersion = $matches['version'][$key];
// We only have a Version or a browser so use what we have.
$this->browserVersion = $matches['version'][0];
}
} else {
// We only have a Version or a browser so use what we have.
$this->browserVersion = $matches['version'][0];
}
}
}
Expand Down

0 comments on commit 608393d

Please sign in to comment.