Http/UserAgent.php
Zend Framework
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to [email protected] so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Http_UserAgent
- Subpackage
- UserAgent
\Zend_Http_UserAgent
Lists of User Agent chains for testing :
- http://www.useragentstring.com/layout/useragentstring.php
- http://user-agent-string.info/list-of-ua
- http://www.user-agents.org/allagents.xml
- http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones
- http://www.mobilemultimedia.be/fr/
- Implements
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Constants
DEFAULT_IDENTIFICATION_SEQUENCE
= 'mobile,desktop''desktop' by default if the sequence return false for each item or is empty
DEFAULT_PERSISTENT_STORAGE_ADAPTER
= 'Session'Default persitent storage adapter : Session or NonPersitent
DEFAULT_HTTP_USER_AGENT
= 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'Default User Agent chain to prevent empty value
Properties

array $_browserTypeClass = array()Browser type class
Map of browser types to classes.
array()Details- Type
- array

array $_config = array('identification_sequence' => self::DEFAULT_IDENTIFICATION_SEQUENCE, 'storage' => array('adapter' => self::DEFAULT_PERSISTENT_STORAGE_ADAPTER))Array to store config
Default values are provided to ensure specific keys are present at instantiation.
array('identification_sequence' => self::DEFAULT_IDENTIFICATION_SEQUENCE, 'storage' => array('adapter' => self::DEFAULT_PERSISTENT_STORAGE_ADAPTER))Details- Type
- array

bool $_immutable = falseWhether or not this instance is immutable.
If true, none of the following may be modified: - $_server - $_browserType - User-Agent (defined in $_server) - HTTP Accept value (defined in $_server) - $_storage
falseDetails- Type
- bool

array $_loaderTypes = array('storage', 'device')Valid plugin loader types
array('storage', 'device')Details- Type
- array

array $_matchLog = array()Trace of items matched to identify the browser type
array()Details- Type
- array
Methods

__construct(null | array | \Zend_Config | \ArrayAccess $options = null) : voidConstructor
| Name | Type | Description |
|---|---|---|
| $options | null | array | \Zend_Config | \ArrayAccess |

_getUserAgentDevice(string $browserType) : stringLoads class for a user agent device
| Name | Type | Description |
|---|---|---|
| $browserType | string | Browser type |
| Type | Description |
|---|---|
| string |
| Exception | Description |
|---|---|
| \Zend_Loader_PluginLoader_Exception | if unable to load UA device |

_match(string $deviceClass) : boolComparison of the UserAgent chain and browser signatures.
The comparison is case-insensitive : the browser signatures must be in lower case
| Name | Type | Description |
|---|---|---|
| $deviceClass | string | Name of class against which a match will be attempted |
| Type | Description |
|---|---|
| bool |

_matchUserAgent() : \Zend_Http_UserAgent_ResultRun the identification sequence to match the right browser type according to the user agent
| Type | Description |
|---|---|
| \Zend_Http_UserAgent_Result |

_validateLoaderType(string $type) : stringValidate a plugin loader type
Verifies that it is in $_loaderTypes, and returns a normalized version of the type.
| Name | Type | Description |
|---|---|---|
| $type | string |
| Type | Description |
|---|---|
| string |
| Exception | Description |
|---|---|
| \Zend_Http_UserAgent_Exception | on invalid type |

clearStorage(string $browser = null) : voidClean the persistent storage
| Name | Type | Description |
|---|---|---|
| $browser | string | Browser identifier (User Agent chain) |

getDevice() : \Zend_Http_UserAgent_DeviceReturns the device object
This is the object that will contain the various discovered device capabilities.
| Type | Description |
|---|---|
| \Zend_Http_UserAgent_Device | $device |

getHttpAccept(string $httpAccept = null) : stringReturns the HTTP Accept server param
| Name | Type | Description |
|---|---|---|
| $httpAccept | string | (option) forced HTTP Accept chain |
| Type | Description |
|---|---|
| string |

getPluginLoader(string $type) : \Zend_Loader_PluginLoaderGet a plugin loader
| Name | Type | Description |
|---|---|---|
| $type | string | A valid plugin loader type; see {@link $_loaderTypes} |
| Type | Description |
|---|---|
| \Zend_Loader_PluginLoader |

getServer() : arrayRetrieve the "$_SERVER" array
Basically, the $_SERVER array or an equivalent container storing the data that will be introspected.
If the value has not been previously set, it sets itself from the $_SERVER superglobal.
| Type | Description |
|---|---|
| array |

getServerValue(string $key) : mixedRetrieve a server value
| Name | Type | Description |
|---|---|---|
| $key | string |
| Type | Description |
|---|---|
| mixed |

getStorage(string $browser = null) : \Zend_Http_UserAgent_StorageReturns the persistent storage handler
Session storage is used by default unless a different storage adapter has been set via the "persistent_storage_adapter" key. That key should contain either a fully qualified class name, or a short name that resolves via the plugin loader.
| Name | Type | Description |
|---|---|---|
| $browser | string | Browser identifier (User Agent chain) |
| Type | Description |
|---|---|
| \Zend_Http_UserAgent_Storage |

getUserAgent() : stringReturns the User Agent value
If $userAgent param is null, the value of $_server['HTTP_USER_AGENT'] is returned.
| Type | Description |
|---|---|
| string |

setBrowserType(string $browserType) : \Zend_Http_UserAgentSet the browser "type"
| Name | Type | Description |
|---|---|---|
| $browserType | string |
| Type | Description |
|---|---|
| \Zend_Http_UserAgent |

setConfig(mixed $config = array()) : \Zend_Http_UserAgentConfig parameters is an Array or a Zend_Config object
The allowed parameters are : - the identification sequence (can be empty) => desktop browser type is the default browser type returned $config['identification_sequence'] : ',' separated browser types - the persistent storage adapter $config['persistent_storage_adapter'] = "Session" or "NonPersistent" - to add or replace a browser type device $config[(type)]['device']['path'] $config[(type)]['device']['classname'] - to add or replace a browser type features adapter $config[(type)]['features']['path'] $config[(type)]['features']['classname']
| Name | Type | Description |
|---|---|---|
| $config | mixed | (option) Config array |
| Type | Description |
|---|---|
| \Zend_Http_UserAgent |

setHttpAccept(string $httpAccept) : \Zend_Http_UserAgentForce or replace the HTTP_ACCEPT chain in self::$_server variable
| Name | Type | Description |
|---|---|---|
| $httpAccept | string | Forced HTTP Accept chain |
| Type | Description |
|---|---|
| \Zend_Http_UserAgent |

setOptions(array | \Zend_Config | \ArrayAccess $options) : \Zend_Http_UserAgentConfigure instance
| Name | Type | Description |
|---|---|---|
| $options | array | \Zend_Config | \ArrayAccess |
| Type | Description |
|---|---|
| \Zend_Http_UserAgent |

setPluginLoader(string $type, string | \Zend_Loader_PluginLoader $loader) : \Zend_Http_UserAgentSet plugin loader
| Name | Type | Description |
|---|---|---|
| $type | string | Type of plugin loader; one of 'storage', (?) |
| $loader | string | \Zend_Loader_PluginLoader |
| Type | Description |
|---|---|
| \Zend_Http_UserAgent |

setServer(array | \ArrayAccess $server) : voidSet the "$_SERVER" array
Basically, the $_SERVER array or an equivalent container storing the data that will be introspected.
| Name | Type | Description |
|---|---|---|
| $server | array | \ArrayAccess |
| Exception | Description |
|---|---|
| \Zend_Http_UserAgent_Exception | on invalid parameter |

setServerValue(string | int | float $key, mixed $value) : voidSet a server value
| Name | Type | Description |
|---|---|---|
| $key | string | int | float | |
| $value | mixed |

setStorage(\Zend_Http_UserAgent_Storage $storage) : \Zend_Http_UserAgentSets the persistent storage handler
| Name | Type | Description |
|---|---|---|
| $storage | \Zend_Http_UserAgent_Storage |
| Type | Description |
|---|---|
| \Zend_Http_UserAgent |

setUserAgent(string $userAgent) : \Zend_Http_UserAgentForce or replace the UA chain in $_server variable
| Name | Type | Description |
|---|---|---|
| $userAgent | string | Forced UserAgent chain |
| Type | Description |
|---|---|
| \Zend_Http_UserAgent |