\Mobi_Mtld_DA_ApiCached

This class significantly improves core DA PHP Api performance when used on a standard website with a single detection per request.

Current optimizations consists of two main parts:

1) tree optimizer - speeds up loading the json file
2) cache provider - caches the results

Typical usage:

$ua = $_SERVER['HTTP_USER_AGENT'];

$da_cache_provider = new Mobi_Mtld_DA_CacheProvider_FileCacheProvider();
$da_api_cached = new Mobi_Mtld_DA_ApiCached("json/sample.json",
                                            $da_cache_provider);

$properties = $da_api_cached->getProperties($ua);

Client side properties

Client side properties can be collected and merged into the results by using the DeviceAtlas Javascript detection file. The results from the client side are sent to the server inside a cookie. The contents of this cookie can be passed to the DeviceAtlas getProperty and getProperties methods. The client side properties over-ride any data file properties and also serve as an input into additional logic to determine other properties such as the iPhone models that are otherwise not detectable. The following code shows how this can be done:

$ua = $_SERVER['HTTP_USER_AGENT'];

// Get the cookie containing the client side properties
$cookie_contents = null;
if (isset($_COOKIE['DAPROPS'])){
  $cookie_contents = $_COOKIE['DAPROPS'];
}

$da_cache_provider = new Mobi_Mtld_DA_CacheProvider_FileCacheProvider();
$da_api_cached = new Mobi_Mtld_DA_ApiCached("json/sample.json",
                                            $da_cache_provider);

$properties = $da_api_cached->getProperties($ua, $cookie_contents);

Note:

It is not recommended to use ApiCached extension for batch processing (i.e. multiple User-Agent detections during a single request). In these situations use standard API interface.

See Api.php for more information

Summary

Methods
Properties
Constants
__construct()
getProperties()
getProperty()
setUseSysTempDir()
clearTreeOptimizerCache()
populateTreeOptimizerCache()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$deviceApi
$config
$pathToJson
N/A

Properties

$deviceApi

$deviceApi : 

Type

$config

$config : 

Type

$pathToJson

$pathToJson : 

Type

Methods

__construct()

__construct(string  $pathToJson, \Mobi_Mtld_DA_CacheProvider_CacheProviderInterface  $cacheProvider = null, boolean  $useTreeOptimizer = true, string  $treeOptimizerCacheDir = null, boolean  $includeChangeableUserAgentProperties = true) 

Creates new instance of Mobi_Mtld_DA_ApiCached object

Parameters

string $pathToJson

The location of the file to read in.

\Mobi_Mtld_DA_CacheProvider_CacheProviderInterface $cacheProvider
boolean $useTreeOptimizer
string $treeOptimizerCacheDir

Cache directory for the tree optimizer; uses sys_get_temp_dir() by default

boolean $includeChangeableUserAgentProperties

Also detect changeable user-agent properties

getProperties()

getProperties(string  $userAgent, string|null  $cookie = null) : array

Returns an array of known properties (as strings) for the user agent

Parameters

string $userAgent

String from the device's User-Agent header

string|null $cookie

The contents of the cookie containing the client side properties

Throws

\Mobi_Mtld_DA_Exception_JsonException

Returns

array —

properties Property name => Property value

getProperty()

getProperty(string  $userAgent, string  $property, string|null  $cookie = null) : string

Returns a value for the named property for this user agent

Parameters

string $userAgent

String from the device's User-Agent header

string $property

The name of the property to return

string|null $cookie

The contents of the cookie containing the client side properties

Throws

\Mobi_Mtld_DA_Exception_UnknownPropertyException
\Mobi_Mtld_DA_Exception_InvalidPropertyException
\Mobi_Mtld_DA_Exception_JsonException

Returns

string —

property

setUseSysTempDir()

setUseSysTempDir(boolean  $useSysTempDir) 

DEPRECATED, not functional

Parameters

boolean $useSysTempDir

clearTreeOptimizerCache()

clearTreeOptimizerCache() 

Deletes all TreeOptimizer cache files

populateTreeOptimizerCache()

populateTreeOptimizerCache(  $force = false) 

Automatically populate full TreeOptimizer cache

Parameters

$force