API_VERSION
API_VERSION = 'DEVICEATLAS_API_VERSION'
Api version.
The DeviceAtlas device detection API provides a way to detect devices based on the HTTP headers. Using the headers, the API returns device properties such as screen width, screen height, is mobile, vendor, model etc. If you want to use the DeviceAtlas API for web applications then it is recommended to use DeviceApiWeb instead of this library.<br/> The DeviceApiWeb is preferred when you want to get the properties from a real-time detection on user's device in a web application.
The DeviceApi is preferred when you want to get the properties from an
off-line user-agent list or header set.
To get the most accurate results: 1- Pass the whole HTTP headers.
2- Use the DeviceAtlas client-side-component and pass the result.
Valid inputs are:
$deviceApi->getProperties((array) headers, string clientSide)
$deviceApi->getProperties((array) headers)
$deviceApi->getProperties(string userAgent, string clientSide)
$deviceApi->getProperties(string userAgent)
Example usage:
$headers = array( "user-agent" => "...", "accept-language" => "...", // add any other available header... ); // require_once "/PATH/TO/Api/Device/DeviceApi.php"; $deviceApi = new Mobi_Mtld_DA_Device_DeviceApi(); try { $deviceApi->loadDataFromFile("/path/to/datafile.json"); // get all properties from the headers $props = $deviceApi->getProperties($headers); // .... use the properties .... if ($props->contains("isMobilePhone", true)) { // it is a mobile phone } // check if property exists then get the property value $displayWidth = $props->containsKey("displayWidth")? $props->get("displayWidth")->asInteger(): 100; // the most easy way to get a property value $deviceModel = $props->model; // null or string } catch (...
__construct(\Mobi_Mtld_DA_Device_Config $config = null)
Constructs a DeviceApi instance with custom configs.
\Mobi_Mtld_DA_Device_Config | $config |
setConfig(\Mobi_Mtld_DA_Device_Config $config = null)
Set new config settings via a new Config object and drop current cache.
\Mobi_Mtld_DA_Device_Config | $config |
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.
$jsonDataFilePath |
getPropertyNames() : array
Get a set of available device property names.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275A set of available device property names as PropertyName objects. A PropertyName object holds a property-name and it's data-type
getApiVersion() : string
Get DeviceApi version.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275DeviceApi version
getDataVersion() : string
Get the device data (JSON file) version.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275The data version
getDataCreationTimestamp() : string
Get the device data creation (JSON file) timestamp.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275The string data creation timestamp
getDataRevision() : integer
Get the device data generation revision.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275Data generation revision
getProperties( $headers = null, $clientSideProperties = null) : \Mobi_Mtld_DA_Properties
$headers | ||
$clientSideProperties |
A set of properties (Property objects) wrapped in a Properties object
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.
$userAgent | ||
$clientSideProperties |
A set of properties (Property objects) wrapped in a Properties object
getLookupSource() : string
Get the source properties fetch source to be used for debugging.
Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275 Warning: count(): Parameter must be an array or an object that implements Countable in /opt/phpdoc/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275The value of one this constants: LOOKUP_SOURCE_TREE or LOOKUP_SOURCE_OPTIMIZED_TREE or LOOKUP_SOURCE_CACHE
normaliseKeys( $keyVals)
Normalise the HTTP header keys, replaces "_" with "-" and removes any HTTP_ prefix
$keyVals |
getPropertyTypeAsByte( $typeChar)
Convert tree property types to interface data types
$typeChar |
addLanguageProperties( $acceptLanguage)
Get the Accept-Language header and add language properties to the property list
$acceptLanguage |