Documentation

ConnectionInformation
in package

FinalYes

CombinedBrowserDetector

  • Primary parser: WhichBrowser\Parser (if available)
  • Optional extension: Browscap (if $extends === true and browscap lib available)
  • Results: WhichBrowser result augmented with Browscap (when present)

Safe: does not attempt to require composer autoload - assumes application bootstraped composer.

Table of Contents

Properties

$browscap  : Browscap|null
static instances
$browscapAvailable  : bool
$browscapClass  : string|null
$browscapInstance  : object|null
$cache  : array<string, array<string, mixed>>
$extends  : bool
$logger  : T4LOG
$parsed  : array<string, mixed>
$userAgent  : string
$whichBrowserClass  : string|null

Methods

__construct()  : mixed
Construct detector.
browscapUpdate()  : void
debugState()  : array<string|int, mixed>
Return internal debug state
getBrowscapClass()  : string|null
getBrowserName()  : string
getBrowserVersion()  : string|null
getDevice()  : array<string|int, mixed>|null
getEngine()  : string|null
getPlatform()  : string
getUserAgent()  : string
getWhichBrowserClass()  : string|null
isBot()  : bool
isBrowserVersion()  : bool
Compare browser version using version_compare.
isBrowserVersionAtLeast()  : bool
isDesktop()  : bool
isMobile()  : bool
isTablet()  : bool
refresh()  : void
Force refresh parsing (clears instance parsed result and updates cache entry).
supportsCookies()  : bool
supportsCssLevel()  : bool
Check CSS level support heuristically.
supportsJavascript()  : bool
toArray()  : array<string|int, mixed>
Return raw combined parse array: [ 'userAgent' => string, 'whichbrowser' => array|null, 'browscap' => array|null, 'combined' => array ]
cacheKey()  : string
initBrowscap()  : void
mergePreferFirst()  : array<string, mixed>
Merge two associative arrays preferring keys present in $a (first argument).
normalizeWhichBrowser()  : array<string|int, mixed>
normalizeWhichBrowserResult()  : array<string, mixed>
Safe normalization of WhichBrowser Parser object to associative array.
normalizeWichBrowscap()  : array<string|int, mixed>
parse()  : array<string|int, mixed>
parseAndCombine()  : array<string, mixed>
Parse with WhichBrowser (if available) then augment with Browscap (if requested/available).
parseBrowscap()  : array<string|int, mixed>
queryBrowscap()  : array<string, mixed>|null
Query browscap data for UA in a tolerant manner.
uaCacheKey()  : string
Create uid key for cache

Properties

$browscapAvailable

private static bool $browscapAvailable = false

whether Browscap class/library is available

$browscapClass

private static string|null $browscapClass = null

last Browscap class discovered (for debug)

$browscapInstance

private static object|null $browscapInstance = null

static Browscap instance (if available)

$extends

private bool $extends

whether to attempt to use Browscap to extend WhichBrowser data

$whichBrowserClass

private static string|null $whichBrowserClass = null

last WhichBrowser class discovered (for debug)

Methods

__construct()

Construct detector.

public __construct(CacheInterface $cache, T4LOG $logger[, string|null $userAgent = null ][, bool $extends = false ]) : mixed
Parameters
$cache : CacheInterface
$logger : T4LOG
$userAgent : string|null = null

UA string; if null, uses $_SERVER['HTTP_USER_AGENT'] or empty string

$extends : bool = false

If true, attempt to augment WhichBrowser with Browscap where possible

browscapUpdate()

public static browscapUpdate(CacheInterface $cache, T4LOG $logger) : void
Parameters
$cache : CacheInterface
$logger : T4LOG

debugState()

Return internal debug state

public debugState() : array<string|int, mixed>
Return values
array<string|int, mixed>

getBrowscapClass()

public static getBrowscapClass() : string|null
Return values
string|null

getDevice()

public getDevice() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null

getWhichBrowserClass()

public static getWhichBrowserClass() : string|null
Return values
string|null

isBrowserVersion()

Compare browser version using version_compare.

public isBrowserVersion(string $version[, string $operator = '>=' ]) : bool
Parameters
$version : string
$operator : string = '>='

one of >, >=, <, <=, ==, !=

Return values
bool

isBrowserVersionAtLeast()

public isBrowserVersionAtLeast(string $version) : bool
Parameters
$version : string
Return values
bool

refresh()

Force refresh parsing (clears instance parsed result and updates cache entry).

public refresh([bool $recreateBrowscap = false ]) : void
Parameters
$recreateBrowscap : bool = false

If true, attempt to re-instantiate browscap

supportsCssLevel()

Check CSS level support heuristically.

public supportsCssLevel([int $level = 3 ]) : bool
Parameters
$level : int = 3

1..3

Return values
bool

toArray()

Return raw combined parse array: [ 'userAgent' => string, 'whichbrowser' => array|null, 'browscap' => array|null, 'combined' => array ]

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

initBrowscap()

private initBrowscap(CacheInterface $cache, LoggerInterface $logger) : void
Parameters
$cache : CacheInterface
$logger : LoggerInterface

mergePreferFirst()

Merge two associative arrays preferring keys present in $a (first argument).

private mergePreferFirst(array<string, mixed> $a, array<string, mixed> $b) : array<string, mixed>

If $a lacks a key but $b has it, take from $b.

Parameters
$a : array<string, mixed>
$b : array<string, mixed>
Return values
array<string, mixed>

normalizeWhichBrowser()

private normalizeWhichBrowser(Parser $parser) : array<string|int, mixed>
Parameters
$parser : Parser
Return values
array<string|int, mixed>

normalizeWhichBrowserResult()

Safe normalization of WhichBrowser Parser object to associative array.

private normalizeWhichBrowserResult(object $parser) : array<string, mixed>

Because WhichBrowser Parser returns nested objects, and different versions vary, this method extracts the most important fields in a stable shape.

Parameters
$parser : object
Return values
array<string, mixed>

normalizeWichBrowscap()

private normalizeWichBrowscap(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>
Return values
array<string|int, mixed>

parseAndCombine()

Parse with WhichBrowser (if available) then augment with Browscap (if requested/available).

private parseAndCombine() : array<string, mixed>
Return values
array<string, mixed>

parseBrowscap()

private parseBrowscap() : array<string|int, mixed>
Return values
array<string|int, mixed>

queryBrowscap()

Query browscap data for UA in a tolerant manner.

private queryBrowscap(string $ua) : array<string, mixed>|null

Supports:

  • BrowscapPHP\Browscap->getBrowser($ua, true) returning array
  • Browscap\Browscap->getBrowser()
  • native get_browser($ua, true) as fallback if browscapClass == 'native_get_browser'
Parameters
$ua : string
Return values
array<string, mixed>|null

uaCacheKey()

Create uid key for cache

private uaCacheKey(string $ua, bool $extends) : string
Parameters
$ua : string
$extends : bool
Return values
string
On this page

Search results