Skip to content

Commit 608393d

Browse files
authored
fix php 8.1 deprecation in WebClient (#121)
1 parent 96d279d commit 608393d

File tree

1 file changed

+57
-55
lines changed

1 file changed

+57
-55
lines changed

src/Web/WebClient.php

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -280,64 +280,66 @@ public function __get($name)
280280
*/
281281
protected function detectBrowser($userAgent)
282282
{
283-
$patternBrowser = '';
284-
285-
// Attempt to detect the browser type. Obviously we are only worried about major browsers.
286-
if ((\stripos($userAgent, 'MSIE') !== false) && (\stripos($userAgent, 'Opera') === false)) {
287-
$this->browser = self::IE;
288-
$patternBrowser = 'MSIE';
289-
} elseif (\stripos($userAgent, 'Trident') !== false) {
290-
$this->browser = self::IE;
291-
$patternBrowser = ' rv';
292-
} elseif (\stripos($userAgent, 'Edge') !== false) {
293-
$this->browser = self::EDGE;
294-
$patternBrowser = 'Edge';
295-
} elseif (\stripos($userAgent, 'Edg') !== false) {
296-
$this->browser = self::EDG;
297-
$patternBrowser = 'Edg';
298-
} elseif ((\stripos($userAgent, 'Firefox') !== false) && (\stripos($userAgent, 'like Firefox') === false)) {
299-
$this->browser = self::FIREFOX;
300-
$patternBrowser = 'Firefox';
301-
} elseif (\stripos($userAgent, 'OPR') !== false) {
302-
$this->browser = self::OPERA;
303-
$patternBrowser = 'OPR';
304-
} elseif (\stripos($userAgent, 'Chrome') !== false) {
305-
$this->browser = self::CHROME;
306-
$patternBrowser = 'Chrome';
307-
} elseif (\stripos($userAgent, 'Safari') !== false) {
308-
$this->browser = self::SAFARI;
309-
$patternBrowser = 'Safari';
310-
} elseif (\stripos($userAgent, 'Opera') !== false) {
311-
$this->browser = self::OPERA;
312-
$patternBrowser = 'Opera';
313-
}
314-
315-
// If we detected a known browser let's attempt to determine the version.
316-
if ($this->browser) {
317-
// Build the REGEX pattern to match the browser version string within the user agent string.
318-
$pattern = '#(?<browser>Version|' . $patternBrowser . ')[/ :]+(?<version>[0-9.|a-zA-Z.]*)#';
319-
320-
// Attempt to find version strings in the user agent string.
321-
$matches = [];
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+
}
322315

323-
if (\preg_match_all($pattern, $userAgent, $matches)) {
324-
// Do we have both a Version and browser match?
325-
if (\count($matches['browser']) == 2) {
326-
// See whether Version or browser came first, and use the number accordingly.
327-
if (\strripos($userAgent, 'Version') < \strripos($userAgent, $patternBrowser)) {
328-
$this->browserVersion = $matches['version'][0];
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+
}
329339
} else {
330-
$this->browserVersion = $matches['version'][1];
331-
}
332-
} elseif (\count($matches['browser']) > 2) {
333-
$key = \array_search('Version', $matches['browser']);
334-
335-
if ($key) {
336-
$this->browserVersion = $matches['version'][$key];
340+
// We only have a Version or a browser so use what we have.
341+
$this->browserVersion = $matches['version'][0];
337342
}
338-
} else {
339-
// We only have a Version or a browser so use what we have.
340-
$this->browserVersion = $matches['version'][0];
341343
}
342344
}
343345
}

0 commit comments

Comments
 (0)