PHP Class DeviceDetector\DeviceDetector

Magic Device Type Methods
ファイルを表示 Open project: piwik/device-detector Class Usage Examples

Public Properties

Property Type Description
$clientTypes array Holds all registered client types

Protected Properties

Property Type Description
$bot array | boolean If $discardBotInformation is set to true, this property will be set to true if parsed UA is identified as bot, additional information will be not available If $skipBotDetection is set to true, bot detection will not be performed and isBot will always be false
$brand string Holds the device brand data after parsing the UA
$cache DeviceDetector\Cache\Cache | Doctrine\Common\Cache\CacheProvider Holds the cache class used for caching the parsed yml-Files
$client array Holds the client data after parsing the UA
$clientParsers DeviceDetector\Parser\Client\ClientParserAbstract[]
$desktopOsArray array Operating system families that are known as desktop only
$device string Holds the device type after parsing the UA
$deviceParsers DeviceDetector\Parser\Device\DeviceParserAbstract[]
$discardBotInformation boolean
$model string Holds the device model data after parsing the UA
$os array Holds the operating system data after parsing the UA
$skipBotDetection boolean
$userAgent string Holds the useragent that should be parsed
$yamlParser DeviceDetector\Yaml\Parser Holds the parser class used for parsing yml-Files

Public Methods

Method Description
__call ( $methodName, $arguments )
__construct ( string $userAgent = '' ) Constructor
addClientParser ( DeviceDetector\Parser\Client\ClientParserAbstract | string $parser )
addDeviceParser ( DeviceParserAbstract | string $parser )
discardBotInformation ( boolean $discard = true ) Sets whether to discard additional bot information If information is discarded it's only possible check whether UA was detected as bot or not.
getBot ( ) : array Returns the bot extracted from the parsed UA
getBrand ( ) : string Returns the device brand extracted from the parsed UA
getBrandName ( ) : string Returns the full device brand name extracted from the parsed UA
getCache ( ) : CacheProvider Returns Cache object
getClient ( string $attr = '' ) : array | string Returns the client data extracted from the parsed UA
getClientParsers ( )
getDevice ( ) : integer | null Returns the device type extracted from the parsed UA
getDeviceName ( ) : string Returns the device type extracted from the parsed UA
getDeviceParsers ( )
getInfoFromUserAgent ( string $ua ) : array Parses a useragent and returns the detected data
getModel ( ) : string Returns the device model extracted from the parsed UA
getOs ( string $attr = '' ) : array | string Returns the operating system data extracted from the parsed UA
getUserAgent ( ) : string Returns the user agent that is set to be parsed
getYamlParser ( ) : DeviceDetector\Yaml\Parser Returns Yaml Parser object
isBot ( ) : boolean Returns if the parsed UA was identified as a Bot
isDesktop ( ) : boolean Returns if the parsed UA was identified as desktop device Desktop devices are all devices with an unknown type that are running a desktop os
isMobile ( )
isParsed ( ) : boolean Returns true, if userAgent was already parsed with parse()
isTouchEnabled ( ) : boolean Returns if the parsed UA was identified as a touch enabled device
parse ( ) Triggers the parsing of the current user agent
setCache ( DeviceDetector\Cache\Cache | CacheProvider $cache ) Sets the Cache class
setUserAgent ( string $userAgent ) Sets the useragent to be parsed
setYamlParser ( $yamlParser ) Sets the Yaml Parser class
skipBotDetection ( boolean $skip = true ) Sets whether to skip bot detection.

Protected Methods

Method Description
hasAndroidMobileFragment ( ) : boolean Returns if the parsed UA contains the 'Android; Mobile;' fragment
hasAndroidTableFragment ( ) : boolean Returns if the parsed UA contains the 'Android; Tablet;' fragment
matchUserAgent ( $regex )
parseBot ( ) Parses the UA for bot information using the Bot parser
parseClient ( )
parseDevice ( )
parseOs ( )
reset ( )
usesMobileBrowser ( )

Method Details

__call() public method

public __call ( $methodName, $arguments )

__construct() public method

Constructor
public __construct ( string $userAgent = '' )
$userAgent string UA to parse

addClientParser() public method

public addClientParser ( DeviceDetector\Parser\Client\ClientParserAbstract | string $parser )
$parser DeviceDetector\Parser\Client\ClientParserAbstract | string

addDeviceParser() public method

public addDeviceParser ( DeviceParserAbstract | string $parser )
$parser DeviceDetector\Parser\Device\DeviceParserAbstract | string

discardBotInformation() public method

(Discarding information speeds up the detection a bit)
public discardBotInformation ( boolean $discard = true )
$discard boolean

getBot() public method

Returns the bot extracted from the parsed UA
public getBot ( ) : array
return array

getBrand() public method

Returns the device brand extracted from the parsed UA
See also: self::$deviceBrand for available device brands
public getBrand ( ) : string
return string

getBrandName() public method

Returns the full device brand name extracted from the parsed UA
See also: self::$deviceBrand for available device brands
public getBrandName ( ) : string
return string

getCache() public method

Returns Cache object
public getCache ( ) : CacheProvider
return Doctrine\Common\Cache\CacheProvider

getClient() public method

If $attr is given only that property will be returned
public getClient ( string $attr = '' ) : array | string
$attr string property to return(optional)
return array | string

getClientParsers() public method

public getClientParsers ( )

getDevice() public method

Returns the device type extracted from the parsed UA
See also: DeviceParserAbstract::$deviceTypes for available device types
public getDevice ( ) : integer | null
return integer | null

getDeviceName() public method

Returns the device type extracted from the parsed UA
See also: DeviceParserAbstract::$deviceTypes for available device types
public getDeviceName ( ) : string
return string

getDeviceParsers() public method

public getDeviceParsers ( )

getInfoFromUserAgent() public static method

ATTENTION: Use that method only for testing or very small applications To get fast results from DeviceDetector you need to make your own implementation, that should use one of the caching mechanisms. See README.md for more information.
Deprecation:
public static getInfoFromUserAgent ( string $ua ) : array
$ua string UserAgent to parse
return array

getModel() public method

Returns the device model extracted from the parsed UA
public getModel ( ) : string
return string

getOs() public method

If $attr is given only that property will be returned
public getOs ( string $attr = '' ) : array | string
$attr string property to return(optional)
return array | string

getUserAgent() public method

Returns the user agent that is set to be parsed
public getUserAgent ( ) : string
return string

getYamlParser() public method

Returns Yaml Parser object
public getYamlParser ( ) : DeviceDetector\Yaml\Parser
return DeviceDetector\Yaml\Parser

hasAndroidMobileFragment() protected method

Returns if the parsed UA contains the 'Android; Mobile;' fragment
protected hasAndroidMobileFragment ( ) : boolean
return boolean

hasAndroidTableFragment() protected method

Returns if the parsed UA contains the 'Android; Tablet;' fragment
protected hasAndroidTableFragment ( ) : boolean
return boolean

isBot() public method

Returns if the parsed UA was identified as a Bot
public isBot ( ) : boolean
return boolean

isDesktop() public method

Returns if the parsed UA was identified as desktop device Desktop devices are all devices with an unknown type that are running a desktop os
See also: self::$desktopOsArray
public isDesktop ( ) : boolean
return boolean

isMobile() public method

public isMobile ( )

isParsed() public method

Returns true, if userAgent was already parsed with parse()
public isParsed ( ) : boolean
return boolean

isTouchEnabled() public method

Note: That only applies to windows 8 tablets
public isTouchEnabled ( ) : boolean
return boolean

matchUserAgent() protected method

protected matchUserAgent ( $regex )

parse() public method

Triggers the parsing of the current user agent
public parse ( )

parseBot() protected method

Parses the UA for bot information using the Bot parser
protected parseBot ( )

parseClient() protected method

protected parseClient ( )

parseDevice() protected method

protected parseDevice ( )

parseOs() protected method

protected parseOs ( )

reset() protected method

protected reset ( )

setCache() public method

Sets the Cache class
public setCache ( DeviceDetector\Cache\Cache | CacheProvider $cache )
$cache DeviceDetector\Cache\Cache | Doctrine\Common\Cache\CacheProvider

setUserAgent() public method

Sets the useragent to be parsed
public setUserAgent ( string $userAgent )
$userAgent string

setYamlParser() public method

Sets the Yaml Parser class
public setYamlParser ( $yamlParser )

skipBotDetection() public method

It is needed if we want bots to be processed as a simple clients. So we can detect if it is mobile client, or desktop, or enything else. By default all this information is not retrieved for the bots.
public skipBotDetection ( boolean $skip = true )
$skip boolean

usesMobileBrowser() protected method

protected usesMobileBrowser ( )

Property Details

$bot protected_oe property

If $discardBotInformation is set to true, this property will be set to true if parsed UA is identified as bot, additional information will be not available If $skipBotDetection is set to true, bot detection will not be performed and isBot will always be false
protected array|bool $bot
return array | boolean

$brand protected_oe property

Holds the device brand data after parsing the UA
protected string $brand
return string

$cache protected_oe property

Holds the cache class used for caching the parsed yml-Files
protected Cache,DeviceDetector\Cache|CacheProvider,Doctrine\Common\Cache $cache
return DeviceDetector\Cache\Cache | Doctrine\Common\Cache\CacheProvider

$client protected_oe property

Holds the client data after parsing the UA
protected array $client
return array

$clientParsers protected_oe property

protected ClientParserAbstract[],DeviceDetector\Parser\Client $clientParsers
return DeviceDetector\Parser\Client\ClientParserAbstract[]

$clientTypes public_oe static_oe property

Holds all registered client types
public static array $clientTypes
return array

$desktopOsArray protected_oe static_oe property

Operating system families that are known as desktop only
protected static array $desktopOsArray
return array

$device protected_oe property

Holds the device type after parsing the UA
protected string $device
return string

$deviceParsers protected_oe property

protected DeviceParserAbstract[],DeviceDetector\Parser\Device $deviceParsers
return DeviceDetector\Parser\Device\DeviceParserAbstract[]

$discardBotInformation protected_oe property

protected bool $discardBotInformation
return boolean

$model protected_oe property

Holds the device model data after parsing the UA
protected string $model
return string

$os protected_oe property

Holds the operating system data after parsing the UA
protected array $os
return array

$skipBotDetection protected_oe property

protected bool $skipBotDetection
return boolean

$userAgent protected_oe property

Holds the useragent that should be parsed
protected string $userAgent
return string

$yamlParser protected_oe property

Holds the parser class used for parsing yml-Files
protected Parser,DeviceDetector\Yaml $yamlParser
return DeviceDetector\Yaml\Parser