API_VERSION
API_VERSION = 'DEVICEATLAS_API_VERSION'
Api version.
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:
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 (...
__construct(\Mobi_Mtld_DA_Device_Config $config = null)
Constructs a DeviceApiWeb 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 |
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.
$headers | ||
$clientSideProperties |
found properties
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