Documentation

BrowserDetector
in package
Uses BackwardCompatibility

Class BrowserDetector This class is an experiment for the job of correctly detecting browsers and settings needed for them.

  • Detects the following browsers
  • Opera, Webkit, Firefox, Web_tv, Konqueror, IE, Gecko
  • Webkit variants: Chrome, iphone, blackberry, android, safari, ipad, ipod
  • Opera Versions: 6, 7, 8 ... 10 ... and mobile mini and mobi
  • Firefox Versions: 1, 2, 3 .... 11 ...
  • Chrome Versions: 1 ... 18 ...
  • IE Versions: 4, 5, 5.5, 6, 7, 8, 9, 10 ... mobile and Mac
  • MS Edge
  • Nokia

Table of Contents

Properties

$obj  : mixed
An instance of this class.
$_browsers  : array<string|int, mixed>
$_is_mobile  : bool
$backcompat  : array<string|int, mixed>

Methods

call()  : mixed
Convenience method.
detectBrowser()  : mixed
The main method of this class, you know the one that does the job: detect the thing.
exportStatic()  : void
Provides a way to export a class's public static properties and methods to global namespace.
isBrowser()  : bool
Are we using this browser?
isEdge()  : bool
Determine if the browser is Edge or not
isFirefox()  : bool
Determine if the browser is Firefox or one of its variants
isGecko()  : bool
Determine if the browser is Gecko or not
isIe()  : bool
Determine if the browser is IE or not
isIe11()  : bool
Determine if the browser is IE11 or not
isKonqueror()  : bool
Determine if the browser is konqueror or not
isOpera()  : bool
Determine if the browser is Opera or not
isOperaMini()  : bool
Determine if the browser is Opera Mini or not
isOperaMobi()  : bool
Determine if the browser is Opera Mobile or not
isWebkit()  : bool
Determine if the browser is a Webkit based one or not
isWebTv()  : bool
Determine if the browser is WebTv or not
fillInformation()  : mixed
Fill out the historical array - needed to support old mods that don't use isBrowser
setupBrowserPriority()  : mixed
Get the browser name that we will use in the <body id="this_browser"> - The order of each browser in $browser_priority is important - if you want to have id='ie6' and not id='ie' then it must appear first in the list of ie browsers - only sets browsers that may need some help via css for compatibility
setupEdge()  : mixed
Sets the version number for MS edge.
setupFirefox()  : mixed
Additional firefox checks.
setupIe()  : mixed
Additional IE checks and settings.
setupOpera()  : mixed
More Opera checks if we are opera.
setupWebkit()  : mixed
Detect Safari / Chrome / iP[ao]d / iPhone / Android / Blackberry from webkit.

Properties

$_browsers

private array<string|int, mixed> $_browsers = []

Holds all the browser information. Its contents will be placed into Utils::$context['browser']

$_is_mobile

private bool $_is_mobile = false

Whether or not this might be a mobile device

$backcompat

private static array<string|int, mixed> $backcompat = ['func_names' => ['call' => 'detectBrowser', 'isBrowser' => 'isBrowser']]

BackwardCompatibility settings for this class.

Methods

detectBrowser()

The main method of this class, you know the one that does the job: detect the thing.

public detectBrowser() : mixed
  • determines the user agent (browser) as best it can.

exportStatic()

Provides a way to export a class's public static properties and methods to global namespace.

public static exportStatic() : void

To do so:

  1. Use this trait in the class.
  2. At the END of the class's file, call its exportStatic() method.

Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.

Regarding the $backcompat items:

A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].

$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.

$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.

Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.

isBrowser()

Are we using this browser?

public static isBrowser(string $browser) : bool
Parameters
$browser : string

The browser we are checking for.

Return values
bool

Whether or not the current browser is what we're looking for.

isEdge()

Determine if the browser is Edge or not

public isEdge() : bool
Return values
bool

Whether or not the browser is Edge

isFirefox()

Determine if the browser is Firefox or one of its variants

public isFirefox() : bool
Return values
bool

Whether or not this is Firefox (or one of its variants)

isGecko()

Determine if the browser is Gecko or not

public isGecko() : bool
Return values
bool

Whether or not this is a Gecko-based browser

isIe()

Determine if the browser is IE or not

public isIe() : bool
Return values
bool

true Whether or not the browser is IE

isIe11()

Determine if the browser is IE11 or not

public isIe11() : bool
Return values
bool

Whether or not the browser is IE11

isKonqueror()

Determine if the browser is konqueror or not

public isKonqueror() : bool
Return values
bool

Whether or not this is Konqueror

isOpera()

Determine if the browser is Opera or not

public isOpera() : bool
Return values
bool

Whether or not this is Opera

isOperaMini()

Determine if the browser is Opera Mini or not

public isOperaMini() : bool
Return values
bool

Whether or not this is Opera Mini

isOperaMobi()

Determine if the browser is Opera Mobile or not

public isOperaMobi() : bool
Return values
bool

Whether or not this is Opera Mobile

isWebkit()

Determine if the browser is a Webkit based one or not

public isWebkit() : bool
Return values
bool

Whether or not this is a Webkit-based browser

isWebTv()

Determine if the browser is WebTv or not

public isWebTv() : bool
Return values
bool

Whether or not this is WebTV

fillInformation()

Fill out the historical array - needed to support old mods that don't use isBrowser

private fillInformation() : mixed

setupBrowserPriority()

Get the browser name that we will use in the <body id="this_browser"> - The order of each browser in $browser_priority is important - if you want to have id='ie6' and not id='ie' then it must appear first in the list of ie browsers - only sets browsers that may need some help via css for compatibility

private setupBrowserPriority() : mixed

setupEdge()

Sets the version number for MS edge.

private setupEdge() : mixed

setupFirefox()

Additional firefox checks.

private setupFirefox() : mixed
  • Gets the version of the FF browser in use
  • Considers all FF variants as FF including IceWeasel, IceCat, Shiretoko and Minefiled

setupIe()

Additional IE checks and settings.

private setupIe() : mixed
  • determines the version of the IE browser in use
  • detects ie4 onward
  • attempts to distinguish between IE and IE in compatibility view
  • checks for old IE on macs as well, since we can

setupOpera()

More Opera checks if we are opera.

private setupOpera() : mixed
  • checks for the version of Opera in use
  • uses checks for 10 first and falls through to <9

setupWebkit()

Detect Safari / Chrome / iP[ao]d / iPhone / Android / Blackberry from webkit.

private setupWebkit() : mixed
  • set the browser version for Safari and Chrome
  • set the mobile flag for mobile based useragents

        
On this page

Search results