\Mobi_Mtld_DA_Device_DeviceApiWeb

A small extension to the core DeviceApi that uses the request HTTP headers for detection and property lookup.<br/><br/>

When detecting user's device as real-time on a website it is strongly recommend to use the DeviceApiWeb library and getProperties as shown bellow.

The getProperties of DeviceApiWeb, automatically detects the availability of the client-side properties and will use them for detection. If you want to have a more accurate detection (specially for apple devices) or have the client side properties included in the property sets, simply include the DeviceAtlas client-side component JavaScript library in the pages.

The API may be configured configured to improve performance and memory footprint, when used in a web application for real-time device detection:

  1. Optimizing the data file.
  2. Caching the results.

The getProperties() method in this class extracts the most suitable headers from the request headers.

Example usage:

// require_once "/PATH/TO/Mobi/Mtld/DeviceApiWeb.php";
// default=the data optimization is on
$deviceApi = new Mobi_Mtld_DA_Device_DeviceApiWeb();
try {
    $deviceApi->loadDataFromFile("/path/to/datafile.json");

    // get all properties from the current request
    $properties = $deviceApi->getProperties();

    // .... use the properties ....
    if ($properties->contains("mobileDevice", true)) {
        if ($properties->containsKey("model")) {
            $deviceModel = $properties->model;
        }
    }
} catch (...

Summary

Methods
Properties
Constants
__construct()
setConfig()
loadDataFromFile()
loadDataFromString()
getPropertyNames()
getApiVersion()
getDataVersion()
getDataCreationTimestamp()
getDataRevision()
getProperties()
getPropertiesFromUa()
getLookupSource()
No public properties found
API_VERSION
MIN_PHP_VERSION
LOOKUP_SOURCE_TREE
LOOKUP_SOURCE_OPTIMIZED_TREE
LOOKUP_SOURCE_CACHE
No protected methods found
$LANGUAGE_HEADER
$config
$tree
N/A
normaliseKeys()
getPropertyTypeAsByte()
addLanguageProperties()
$PROPERTY_NAME_LANGUAGE
$PROPERTY_NAME_LANGUAGE_LOCALE
N/A

Constants

API_VERSION

API_VERSION = 'DEVICEATLAS_API_VERSION'

Api version.

MIN_PHP_VERSION

MIN_PHP_VERSION = '5.2.3'

Minimum PHP version required for this API to run. *

LOOKUP_SOURCE_TREE

LOOKUP_SOURCE_TREE = 'tree'

LOOKUP_SOURCE_OPTIMIZED_TREE

LOOKUP_SOURCE_OPTIMIZED_TREE = 'optimized tree'

LOOKUP_SOURCE_CACHE

LOOKUP_SOURCE_CACHE = 'cache'

Properties

$LANGUAGE_HEADER

$LANGUAGE_HEADER : 

Type

$config

$config : 

Type

$tree

$tree : 

Type

$PROPERTY_NAME_LANGUAGE

$PROPERTY_NAME_LANGUAGE : 

Type

$PROPERTY_NAME_LANGUAGE_LOCALE

$PROPERTY_NAME_LANGUAGE_LOCALE : 

Type

Methods

__construct()

__construct(\Mobi_Mtld_DA_Device_Config  $config = null) 

Constructs a DeviceApiWeb instance with custom configs.

Parameters

\Mobi_Mtld_DA_Device_Config $config

setConfig()

setConfig(\Mobi_Mtld_DA_Device_Config  $config = null) 

Set new config settings via a new Config object and drop current cache.

Parameters

\Mobi_Mtld_DA_Device_Config $config

loadDataFromFile()

loadDataFromFile(  $jsonDataFilePath) 

Load the DeviceAtlas device detection data into the API from a JSON file.

The JSON data file is provided by the DeviceAtlas web-site.

Parameters

$jsonDataFilePath

Throws

\IOException
\Mobi_Mtld_DA_Exception_DataFileException
\Mobi_Mtld_DA_Exception_DataReadException
\Mobi_Mtld_DA_Exception_JsonException

loadDataFromString()

loadDataFromString(  $data) 

Load the DeviceAtlas device detection data into the API from a string.

The JSON data file is provided by the DeviceAtlas web-site.

Parameters

$data

Throws

\Mobi_Mtld_DA_Exception_DataFileException
\Mobi_Mtld_DA_Exception_JsonException

getPropertyNames()

getPropertyNames() : array

Get a set of available device property names.

Returns

array —

A set of available device property names as PropertyName objects. A PropertyName object holds a property-name and it's data-type

getApiVersion()

getApiVersion() : string

Get DeviceApi version.

Returns

string —

DeviceApi version

getDataVersion()

getDataVersion() : string

Get the device data (JSON file) version.

Returns

string —

The data version

getDataCreationTimestamp()

getDataCreationTimestamp() : string

Get the device data creation (JSON file) timestamp.

Returns

string —

The string data creation timestamp

getDataRevision()

getDataRevision() : integer

Get the device data generation revision.

Returns

integer —

Data generation revision

getProperties()

getProperties(  $headers = null,   $clientSideProperties = null) : \The

Get the Device properties for the current request. The most suitable request headers are extracted and used for detection and property lookup.<br/> If the client-side-component has been used and the client-side properties exists in the client-side cookie, then the properties will be included.<br/> You can change the API's configs using class "Mobi_Mtld_DA_Device_Config".

Depending on the configs the properties may include user-agent dynamic properties and language/locale properties.

Parameters

$headers
$clientSideProperties

Throws

\Mobi_Mtld_DA_Esception_ClientPropertiesException

Returns

\The —

found properties

getPropertiesFromUa()

getPropertiesFromUa(  $userAgent,   $clientSideProperties = null) : \Mobi_Mtld_DA_Properties

Get the properties for a User-Agent merged with the client-side properties (when provided by the DeviceAtlas client side component).

The DeviceAtlas client-side component (JavaScript library) collects the client-side properties and puts them in a cookie. The contents of this cookie must be passed to this method. The client properties will over-ride any properties discovered from the main JSON data file.

Parameters

$userAgent
$clientSideProperties

Throws

\Mobi_Mtld_DA_Exception_ClientPropertiesException

Returns

\Mobi_Mtld_DA_Properties

A set of properties (Property objects) wrapped in a Properties object

getLookupSource()

getLookupSource() : string

Get the source properties fetch source to be used for debugging.

Returns

string —

The value of one this constants: LOOKUP_SOURCE_TREE or LOOKUP_SOURCE_OPTIMIZED_TREE or LOOKUP_SOURCE_CACHE

normaliseKeys()

normaliseKeys(  $keyVals) 

Normalise the HTTP header keys, replaces "_" with "-" and removes any HTTP_ prefix

Parameters

$keyVals

getPropertyTypeAsByte()

getPropertyTypeAsByte(  $typeChar) 

Convert tree property types to interface data types

Parameters

$typeChar

addLanguageProperties()

addLanguageProperties(  $acceptLanguage) 

Get the Accept-Language header and add language properties to the property list

Parameters

$acceptLanguage