@@ -280,72 +280,74 @@ public function __get($name)
280
280
*/
281
281
protected function detectBrowser ($ userAgent )
282
282
{
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 ;
315
285
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 )) {
341
335
$ 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 ];
342
344
}
345
+ } else {
346
+ // We only have a Version or a browser so use what we have.
347
+ $ this ->browserVersion = $ matches ['version ' ][0 ];
343
348
}
344
349
}
345
350
}
346
-
347
- // Mark this detection routine as run.
348
- $ this ->detection ['browser ' ] = true ;
349
351
}
350
352
351
353
/**
@@ -377,6 +379,13 @@ protected function detectEncoding($acceptEncoding)
377
379
*/
378
380
protected function detectEngine ($ userAgent )
379
381
{
382
+ // Mark this detection routine as run.
383
+ $ this ->detection ['engine ' ] = true ;
384
+
385
+ if (empty ($ userAgent )) {
386
+ return ;
387
+ }
388
+
380
389
if (\stripos ($ userAgent , 'MSIE ' ) !== false || \stripos ($ userAgent , 'Trident ' ) !== false ) {
381
390
// Attempt to detect the client engine -- starting with the most popular ... for now.
382
391
$ this ->engine = self ::TRIDENT ;
@@ -434,9 +443,6 @@ protected function detectEngine($userAgent)
434
443
// Lesser known engine but it finishes off the major list from Wikipedia :-)
435
444
$ this ->engine = self ::AMAYA ;
436
445
}
437
-
438
- // Mark this detection routine as run.
439
- $ this ->detection ['engine ' ] = true ;
440
446
}
441
447
442
448
/**
@@ -468,6 +474,13 @@ protected function detectLanguage($acceptLanguage)
468
474
*/
469
475
protected function detectPlatform ($ userAgent )
470
476
{
477
+ // Mark this detection routine as run.
478
+ $ this ->detection ['platform ' ] = true ;
479
+
480
+ if (empty ($ userAgent )) {
481
+ return ;
482
+ }
483
+
471
484
// Attempt to detect the client platform.
472
485
if (\stripos ($ userAgent , 'Windows ' ) !== false ) {
473
486
$ this ->platform = self ::WINDOWS ;
@@ -526,9 +539,6 @@ protected function detectPlatform($userAgent)
526
539
} elseif (\stripos ($ userAgent , 'Linux ' ) !== false ) {
527
540
$ this ->platform = self ::LINUX ;
528
541
}
529
-
530
- // Mark this detection routine as run.
531
- $ this ->detection ['platform ' ] = true ;
532
542
}
533
543
534
544
/**
@@ -542,9 +552,13 @@ protected function detectPlatform($userAgent)
542
552
*/
543
553
protected function detectRobot ($ userAgent )
544
554
{
545
- $ this ->robot = (bool ) \preg_match ('/http|bot|robot|spider|crawler|curl|^$/i ' , $ userAgent );
546
-
547
555
$ 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 );
548
562
}
549
563
550
564
/**
0 commit comments