Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Http_UserAgent Class Reference

Public Member Functions

 __construct ($options=null)
 Constructor.
 
 serialize ()
 Serialized representation of the object.
 
 unserialize ($serialized)
 Unserialize a previous representation of the object.
 
 setOptions ($options)
 Configure instance.
 
 getUserAgent ()
 Returns the User Agent value.
 
 setUserAgent ($userAgent)
 Force or replace the UA chain in $_server variable.
 
 getHttpAccept ($httpAccept=null)
 Returns the HTTP Accept server param.
 
 setHttpAccept ($httpAccept)
 Force or replace the HTTP_ACCEPT chain in self::$_server variable.
 
 getStorage ($browser=null)
 Returns the persistent storage handler.
 
 setStorage (Zend_Http_UserAgent_Storage $storage)
 Sets the persistent storage handler.
 
 clearStorage ($browser=null)
 Clean the persistent storage.
 
 getConfig ()
 Get user configuration.
 
 setConfig ($config=array())
 Config parameters is an Array or a Zend_Config object.
 
 getDevice ()
 Returns the device object.
 
 getBrowserType ()
 Retrieve the browser type.
 
 setBrowserType ($browserType)
 Set the browser "type".
 
 getServer ()
 Retrieve the "$_SERVER" array.
 
 setServer ($server)
 Set the "$_SERVER" array.
 
 getServerValue ($key)
 Retrieve a server value.
 
 setServerValue ($key, $value)
 Set a server value.
 
 setPluginLoader ($type, $loader)
 Set plugin loader.
 
 getPluginLoader ($type)
 Get a plugin loader.
 

Public Attributes

const DEFAULT_IDENTIFICATION_SEQUENCE = 'mobile,desktop'
 'desktop' by default if the sequence return false for each item or is empty
 
const DEFAULT_PERSISTENT_STORAGE_ADAPTER = 'Session'
 Default persitent storage adapter : Session or NonPersitent.
 
const DEFAULT_BROWSER_TYPE = 'desktop'
 'desktop' by default if the sequence return false for each item
 
const DEFAULT_HTTP_USER_AGENT = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'
 Default User Agent chain to prevent empty value.
 
const DEFAULT_HTTP_ACCEPT = "application/xhtml+xml"
 Default Http Accept param to prevent empty value.
 
const DEFAULT_MARKUP_LANGUAGE = "xhtml"
 Default markup language.
 

Protected Member Functions

 _match ($deviceClass)
 Comparison of the UserAgent chain and browser signatures.
 
 _getUserAgentDevice ($browserType)
 Loads class for a user agent device.
 
 _validateLoaderType ($type)
 Validate a plugin loader type.
 
 _matchUserAgent ()
 Run the identification sequence to match the right browser type according to the user agent.
 
 _createDevice ()
 Creates device object instance.
 

Protected Attributes

 $_browserType
 
 $_browserTypeClass = array()
 
 $_config
 
 $_device
 
 $_immutable = false
 
 $_loaders = array()
 
 $_loaderTypes = array('storage', 'device')
 
 $_matchLog = array()
 
 $_server
 
 $_storage
 

Constructor & Destructor Documentation

__construct (   $options = null)

Constructor.

Parameters
null | array | Zend_Config | ArrayAccess$options
Returns
void

Member Function Documentation

_createDevice ( )
protected

Creates device object instance.

Returns
void
_getUserAgentDevice (   $browserType)
protected

Loads class for a user agent device.

Parameters
string$browserTypeBrowser type
Returns
string
Exceptions
Zend_Loader_PluginLoader_Exceptionif unable to load UA device
_match (   $deviceClass)
protected

Comparison of the UserAgent chain and browser signatures.

The comparison is case-insensitive : the browser signatures must be in lower case

Parameters
string$deviceClassName of class against which a match will be attempted
Returns
bool
_matchUserAgent ( )
protected

Run the identification sequence to match the right browser type according to the user agent.

Returns
Zend_Http_UserAgent_Result
_validateLoaderType (   $type)
protected

Validate a plugin loader type.

Verifies that it is in $_loaderTypes, and returns a normalized version of the type.

Parameters
string$type
Returns
string
Exceptions
Zend_Http_UserAgent_Exceptionon invalid type
clearStorage (   $browser = null)

Clean the persistent storage.

Parameters
string$browserBrowser identifier (User Agent chain)
Returns
void
getBrowserType ( )

Retrieve the browser type.

Returns
string $browserType
getConfig ( )

Get user configuration.

Returns
array
getDevice ( )

Returns the device object.

This is the object that will contain the various discovered device capabilities.

Returns
Zend_Http_UserAgent_Device $device
getHttpAccept (   $httpAccept = null)

Returns the HTTP Accept server param.

Parameters
string$httpAccept(option) forced HTTP Accept chain
Returns
string
getPluginLoader (   $type)

Get a plugin loader.

Parameters
string$typeA valid plugin loader type; see $_loaderTypes
Returns
Zend_Loader_PluginLoader
getServer ( )

Retrieve 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.

Returns
array
getServerValue (   $key)

Retrieve a server value.

Parameters
string$key
Returns
mixed
getStorage (   $browser = null)

Returns 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.

Parameters
string$browserBrowser identifier (User Agent chain)
Returns
Zend_Http_UserAgent_Storage
getUserAgent ( )

Returns the User Agent value.

If $userAgent param is null, the value of $_server['HTTP_USER_AGENT'] is returned.

Returns
string
serialize ( )

Serialized representation of the object.

Returns
string
setBrowserType (   $browserType)

Set the browser "type".

Parameters
string$browserType
Returns
Zend_Http_UserAgent
setConfig (   $config = array())

Config 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']
Parameters
mixed$config(option) Config array
Returns
Zend_Http_UserAgent
setHttpAccept (   $httpAccept)

Force or replace the HTTP_ACCEPT chain in self::$_server variable.

Parameters
string$httpAcceptForced HTTP Accept chain
Returns
Zend_Http_UserAgent
setOptions (   $options)

Configure instance.

Parameters
array | Zend_Config | ArrayAccess$options
Returns
Zend_Http_UserAgent
setPluginLoader (   $type,
  $loader 
)

Set plugin loader.

Parameters
string$typeType of plugin loader; one of 'storage', (?)
string | Zend_Loader_PluginLoader$loader
Returns
Zend_Http_UserAgent
setServer (   $server)

Set the "$_SERVER" array.

Basically, the $_SERVER array or an equivalent container storing the data that will be introspected.

Parameters
array | ArrayAccess$server
Returns
void
Exceptions
Zend_Http_UserAgent_Exceptionon invalid parameter
setServerValue (   $key,
  $value 
)

Set a server value.

Parameters
string | int | float$key
mixed$value
Returns
void
setStorage ( Zend_Http_UserAgent_Storage  $storage)

Sets the persistent storage handler.

Parameters
Zend_Http_UserAgent_Storage$storage
Returns
Zend_Http_UserAgent
setUserAgent (   $userAgent)

Force or replace the UA chain in $_server variable.

Parameters
string$userAgentForced UserAgent chain
Returns
Zend_Http_UserAgent
unserialize (   $serialized)

Unserialize a previous representation of the object.

Parameters
string$serialized
Returns
void

Member Data Documentation

$_browserType
protected
$_browserTypeClass = array()
protected
$_config
protected
Initial value:
= array(
'identification_sequence' => self::DEFAULT_IDENTIFICATION_SEQUENCE,
'storage' => array(
'adapter' => self::DEFAULT_PERSISTENT_STORAGE_ADAPTER,
),
)
$_device
protected
$_immutable = false
protected
$_loaders = array()
protected
$_loaderTypes = array('storage', 'device')
protected
$_matchLog = array()
protected
$_server
protected
$_storage
protected
const DEFAULT_BROWSER_TYPE = 'desktop'

'desktop' by default if the sequence return false for each item

const DEFAULT_HTTP_ACCEPT = "application/xhtml+xml"

Default Http Accept param to prevent empty value.

const DEFAULT_HTTP_USER_AGENT = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'

Default User Agent chain to prevent empty value.

const DEFAULT_IDENTIFICATION_SEQUENCE = 'mobile,desktop'

'desktop' by default if the sequence return false for each item or is empty

const DEFAULT_MARKUP_LANGUAGE = "xhtml"

Default markup language.

const DEFAULT_PERSISTENT_STORAGE_ADAPTER = 'Session'

Default persitent storage adapter : Session or NonPersitent.