TOP

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
Author
DeviceAtlas Limited
Deprecated
This API is deprecated, it is highly recommended to use the new DeviceApi instead.

Methods

__construct

Mobi_Mtld_DA_ApiCached $obj = new Mobi_Mtld_DA_ApiCached(
    string $pathToJson,
    Mobi_Mtld_DA_CacheProvider_CacheProviderInterface $cacheProvider,
    boolean $useTreeOptimizer,
    string $treeOptimizerCacheDir,
    boolean $includeChangeableUserAgentProperties
)

Creates new instance of Mobi_Mtld_DA_ApiCached object

Arguments

    $pathToJson (string)
    The location of the file to read in.
    $useTreeOptimizer (boolean)
    $treeOptimizerCacheDir (string)
    Cache directory for the tree optimizer; uses sys_get_temp_dir() by default
    $includeChangeableUserAgentProperties (boolean)
    Also detect changeable user-agent properties

Returns

void

clearTreeOptimizerCache

void $obj->clearTreeOptimizerCache()

Deletes all TreeOptimizer cache files

Returns

void

getProperties

array $obj->getProperties(string $userAgent, string | null $cookie)

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

Arguments

    $userAgent (string)
    String from the device's User-Agent header
    $cookie (string | null)
    The contents of the cookie containing the client side properties

Returns

array
properties Property name => Property value

Throws

getProperty

string $obj->getProperty(string $userAgent, string $property, string | null $cookie)

Returns a value for the named property for this user agent

Arguments

    $userAgent (string)
    String from the device's User-Agent header
    $property (string)
    The name of the property to return
    $cookie (string | null)
    The contents of the cookie containing the client side properties

Returns

string
property

Throws

populateTreeOptimizerCache

void $obj->populateTreeOptimizerCache()

Automatically populate full TreeOptimizer cache

Returns

void

setUseSysTempDir

void $obj->setUseSysTempDir(boolean $useSysTempDir)

DEPRECATED, not functional

Arguments

    $useSysTempDir (boolean)

Returns

void