$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 (...
Api version.
Minimum PHP version required for this API to run. *
string Mobi_Mtld_DA_Device_DeviceApi::getApiVersion()
Get DeviceApi version.
Mobi_Mtld_DA_Device_DeviceApi $obj = new Mobi_Mtld_DA_Device_DeviceApi( Mobi_Mtld_DA_Device_Config config )
Constructs a DeviceApi instance with custom configs.
string $obj->getDataCreationTimestamp()
Get the device data creation (JSON file) timestamp.
int $obj->getDataRevision()
Get the device data generation revision.
string $obj->getDataVersion()
Get the device data (JSON file) version.
string $obj->getLookupSource()
Get the source properties fetch source to be used for debugging.
Mobi_Mtld_DA_Properties $obj->getProperties( string userAgent, string clientSideProperties=null )
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.
Mobi_Mtld_DA_Properties $obj->getProperties( array headers, string clientSideProperties=null )
Get the properties for a set of HTTP headers merged with properties from the client side component. The DeviceApi gets all the request HTTP headers and will precisely detect the device and find property values by all usable headers. 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.
Mobi_Mtld_DA_Properties $obj->getPropertiesFromUa( string userAgent, string clientSideProperties=null )
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.
array $obj->getPropertyNames()
Get a set of available device property names.
void $obj->loadDataFromFile(string 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.
void $obj->loadDataFromString(string data)
Load the DeviceAtlas device detection data into the API from a string. The JSON data file is provided by the DeviceAtlas web-site.
void $obj->setConfig(Mobi_Mtld_DA_Device_Config $config)
Set new config settings via a new Config object and drop current cache.