API_ID
API_ID = 1
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.<br/><br/>
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 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 (...
buildDataFile( $dataFileDownloadUrl)
$dataFileDownloadUrl |
loadDataFromFile(string $jsonDataFilePath, boolean $refreshCache = false)
Load the DeviceAtlas device detection data into the API from a JSON file.
The JSON data file is provided by the DeviceAtlas website.
string | $jsonDataFilePath | Path to the JSON file |
boolean | $refreshCache | Forces the Tree Optimizer to re-build its cache (DeviceApiWeb interface) |
downloadAndLoadDataFileFromUrl( $dataFile, $dataFileManager = null)
Load the DeviceAtlas data file data from a URL.
Schedule a reload if data file is stale. Re-download data file if local data file is corrupted.
$dataFile | ||
$dataFileManager |
when there is a problem downloading or loading the data file.
scheduleReloadAndFinishRequest( $dataFile, $dataFileManager)
A secondary register_shutdown_call to make sure the reload method is called as the last one.
$dataFile | ||
$dataFileManager |
reload( $dataFile, $dataFileManager, $isScheduled = false)
Downloads a new data file if the existing one is stale.
Loads data file into API.
$dataFile | ||
$dataFileManager | ||
$isScheduled |
__construct(\DeviceAtlas\Device\Config|null $config = null)
Constructs a DeviceApi instance with default or custom config.
\DeviceAtlas\Device\Config|null | $config | An instance of Config, you can change the DeviceAtlas API config by creating an instance of Config and setting your custom config values and then passing the instance to the DeviceApi constructor. null=use default configs. |
saveDataToCache( $jsonDataFilePath)
$jsonDataFilePath |
getPropertyNames() : array
Get a set of all possible property names. Note that the client side properties are not included in this set.
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 all possible device property names as PropertyName objects.
getApiVersion() : string
The version of this API.
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
The version of the data file.
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 device data file version.
getDataCreationTimestamp() : integer
The creation date/time of the loaded data file as a Unix 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 creation date/time of this data file as a Unix timestamp.
getDataCreationIso8601() : string
The creation date/time of the loaded data file in ISO 8601 format.
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 creation date/time of the loaded data file in ISO 8601 format.
getProperties(string|array $identifierOrHeaders, $clientSideString = null) : \DeviceAtlas\Properties
Get the properties for an identifier merged with the client side properties (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 override any properties discovered from the main JSON data file.
string|array | $identifierOrHeaders | An identifier such as a User-Agent or Client Hints model, or map of HTTP headers. |
$clientSideString |
A set of properties (Property objects) wrapped in a Properties object
downloadAndLoadDataFile( $dataFileDownloadUrl)
$dataFileDownloadUrl |
checkReloadSchedule( $dataFile, $dataFileManager, $forceReload = false)
$dataFile | ||
$dataFileManager | ||
$forceReload |
callFailureCallback(\Exception $ex, $dataFile)
Call user defined callback if set.
\Exception | $ex | |
$dataFile |
getDataFromFile( $jsonDataFilePath)
$jsonDataFilePath |
loadDataFromCache( $jsonDataFilePath, $refreshCache = false)
$jsonDataFilePath | ||
$refreshCache |
loadCachedTreeRoot()
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 1275
postLoadDataInitialization()
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 1275
getPropertiesFromHeaders( $headers, $clientSideString = null)
$headers | ||
$clientSideString |
extractLanguageProperties( $properties, $acceptLanguageHeader)
$properties | ||
$acceptLanguageHeader |
getAcceptLanguage( $normalisedHeaders)
$normalisedHeaders |
getPropertiesFromIdentifier(string $identifier, $clientSideString = null) : \DeviceAtlas\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.
string | $identifier | The User-Agent string |
$clientSideString |
A set of properties (Property objects) wrapped in a Properties object
detectProperties( $normalisedHeaders, $clientSideString = null)
$normalisedHeaders | ||
$clientSideString |
extractClientSideInputs( $dynamicProperties, $normalisedHeaders)
The client side string may contain identifiers that can be used for component detection. This method adds these identifiers to the headers map.
$dynamicProperties | ||
$normalisedHeaders |
normaliseHeaders( $headers)
Performs the following on header keys: lowercase, replaces "_" with "-" and strips prefixed "http-" if present.
$headers |
checkIsDataLoaded()
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 1275
cachePut( $identifierOrHeaders, $clientSideString, $properties, $acceptLanguage = null)
$identifierOrHeaders | ||
$clientSideString | ||
$properties | ||
$acceptLanguage |
cacheGet( $identifierOrHeaders, $clientSideString, $acceptLanguage = null)
$identifierOrHeaders | ||
$clientSideString | ||
$acceptLanguage |