DeviceApiWeb
extends DeviceApi
in package
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/>
...
Tags
Table of Contents
Constants
- API_ID = 1
- API_VERSION = '3.1.2'
- LOOKUP_SOURCE_CACHE = 'cache'
- LOOKUP_SOURCE_TREE = 'tree'
- MIN_PHP_VERSION = '7.0'
- XMSG_FILE_NOT_FOUND = 'Unable to read "%s" file, make sure file exists and has read permissions.'
- XMSG_MISSING_DATA = "The device instance failed to initialize: data file should be loaded first"
- XMSG_PROBLEM_READING_FROM_STRING = "Problem reading JSON data from string."
Properties
- $config : mixed
- $ACCEPT_LANGUAGE_HEADER : mixed
- $cacheEnabled : mixed
- $cacheRootJsonFilePath : mixed
- $cacheService : mixed
- $componentDetector : mixed
- $deviceData : mixed
- $optimizerTempDir : mixed
- $propertiesCollector : mixed
- $propertyMappingsRunner : mixed
Methods
- __construct() : mixed
- Constructs a DeviceApiWeb instance with default or custom config.
- buildDataFile() : mixed
- downloadAndLoadDataFile() : mixed
- downloadAndLoadDataFileFromUrl() : mixed
- Load the DeviceAtlas data file data from a URL.
- getApiVersion() : string
- The version of this API.
- getDataCreationIso8601() : string
- The creation date/time of the loaded data file in ISO 8601 format.
- getDataCreationTimestamp() : int
- The creation date/time of the loaded data file as a Unix timestamp.
- getDataVersion() : string
- The version of the data file.
- getProperties() : Properties
- Get the Device properties for the current request. The most suitable request headers are extracted and used for detection and property lookup.
- getPropertyNames() : array<string|int, mixed>
- Get a set of all possible property names. Note that the client side properties are not included in this set.
- loadDataFromFile() : mixed
- loadDataFromString() : mixed
- Load the DeviceAtlas device detection data into the API from a string.
- reload() : mixed
- Downloads a new data file if the existing one is stale.
- saveDataToCache() : mixed
- scheduleReloadAndFinishRequest() : mixed
- A secondary register_shutdown_call to make sure the reload method is called as the last one; when available call fastcgi_finish_request() too, to make sure there is no delay for a visitor/client.
- cacheGet() : mixed
- cachePut() : mixed
- callFailureCallback() : mixed
- Call user defined callback if set.
- checkIsDataLoaded() : mixed
- checkReloadSchedule() : mixed
- detectProperties() : mixed
- extractClientSideInputs() : mixed
- The client side string may contain identifiers that can be used for component detection. This method adds these identifiers to the headers map.
- extractLanguageProperties() : mixed
- getAcceptLanguage() : mixed
- getDataFromFile() : mixed
- getPropertiesFromHeaders() : mixed
- getPropertiesFromIdentifier() : Properties
- Get the properties for a User-Agent merged with the client-side properties (when provided by the DeviceAtlas client side component).
- loadCachedTreeRoot() : mixed
- loadDataFromCache() : mixed
- normaliseHeaders() : mixed
- Performs the following on header keys: lowercase, replaces "_" with "-" and strips prefixed "http-" if present.
- postLoadDataInitialization() : mixed
Constants
API_ID
public
mixed
API_ID
= 1
API_VERSION
public
mixed
API_VERSION
= '3.1.2'
LOOKUP_SOURCE_CACHE
public
mixed
LOOKUP_SOURCE_CACHE
= 'cache'
LOOKUP_SOURCE_TREE
public
mixed
LOOKUP_SOURCE_TREE
= 'tree'
MIN_PHP_VERSION
public
mixed
MIN_PHP_VERSION
= '7.0'
XMSG_FILE_NOT_FOUND
public
mixed
XMSG_FILE_NOT_FOUND
= 'Unable to read "%s" file, make sure file exists and has read permissions.'
XMSG_MISSING_DATA
public
mixed
XMSG_MISSING_DATA
= "The device instance failed to initialize: data file should be loaded first"
XMSG_PROBLEM_READING_FROM_STRING
public
mixed
XMSG_PROBLEM_READING_FROM_STRING
= "Problem reading JSON data from string."
Properties
$config
protected
mixed
$config
$ACCEPT_LANGUAGE_HEADER
private
static mixed
$ACCEPT_LANGUAGE_HEADER
= "accept-language"
$cacheEnabled
private
mixed
$cacheEnabled
= false
$cacheRootJsonFilePath
private
mixed
$cacheRootJsonFilePath
$cacheService
private
mixed
$cacheService
$componentDetector
private
mixed
$componentDetector
$deviceData
private
mixed
$deviceData
$optimizerTempDir
private
mixed
$optimizerTempDir
$propertiesCollector
private
mixed
$propertiesCollector
$propertyMappingsRunner
private
mixed
$propertyMappingsRunner
Methods
__construct()
Constructs a DeviceApiWeb instance with default or custom config.
public
__construct([Config|null $config = null ]) : mixed
Parameters
- $config : Config|null = null
-
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.
Tags
buildDataFile()
public
abstract buildDataFile(mixed $dataFileDownloadUrl) : mixed
Parameters
- $dataFileDownloadUrl : mixed
downloadAndLoadDataFile()
public
downloadAndLoadDataFile(mixed $dataFileDownloadUrl) : mixed
Parameters
- $dataFileDownloadUrl : mixed
downloadAndLoadDataFileFromUrl()
Load the DeviceAtlas data file data from a URL.
public
downloadAndLoadDataFileFromUrl(mixed $dataFile[, mixed $dataFileManager = null ]) : mixed
Schedule a reload if data file is stale. Re-download data file if local data file is corrupted.
Parameters
- $dataFile : mixed
- $dataFileManager : mixed = null
Tags
getApiVersion()
The version of this API.
public
static getApiVersion() : string
Return values
string —DeviceApi version
getDataCreationIso8601()
The creation date/time of the loaded data file in ISO 8601 format.
public
getDataCreationIso8601() : string
Return values
string —The creation date/time of the loaded data file in ISO 8601 format.
getDataCreationTimestamp()
The creation date/time of the loaded data file as a Unix timestamp.
public
getDataCreationTimestamp() : int
Return values
int —The creation date/time of this data file as a Unix timestamp.
getDataVersion()
The version of the data file.
public
getDataVersion() : string
Return values
string —The device data file version.
getProperties()
Get the Device properties for the current request. The most suitable request headers are extracted and used for detection and property lookup.
public
getProperties([string|array<string|int, mixed> $identifierOrHeaders = null ][, mixed $clientSideString = null ]) : Properties
Parameters
- $identifierOrHeaders : string|array<string|int, mixed> = null
-
An identifier such as a User-Agent or Client Hints model, or map of HTTP headers.
- $clientSideString : mixed = null
Tags
Return values
Properties —A set of properties (Property objects) wrapped in a Properties object
getPropertyNames()
Get a set of all possible property names. Note that the client side properties are not included in this set.
public
getPropertyNames() : array<string|int, mixed>
Return values
array<string|int, mixed> —A set of all possible device property names as PropertyName objects.
loadDataFromFile()
public
abstract loadDataFromFile(mixed $jsonDataFilePath) : mixed
Parameters
- $jsonDataFilePath : mixed
loadDataFromString()
Load the DeviceAtlas device detection data into the API from a string.
public
loadDataFromString(string $data) : mixed
The JSON data file is provided by the DeviceAtlas website.
Parameters
- $data : string
-
DeviceAtlas device data
Tags
reload()
Downloads a new data file if the existing one is stale.
public
reload( $dataFile, $dataFileManager[, $isScheduled = false ]) : mixed
Loads data file into API.
Parameters
saveDataToCache()
public
saveDataToCache(mixed $jsonDataFilePath) : mixed
Parameters
- $jsonDataFilePath : mixed
scheduleReloadAndFinishRequest()
A secondary register_shutdown_call to make sure the reload method is called as the last one; when available call fastcgi_finish_request() too, to make sure there is no delay for a visitor/client.
public
scheduleReloadAndFinishRequest( $dataFile, $dataFileManager) : mixed
Parameters
cacheGet()
private
cacheGet(mixed $identifierOrHeaders, mixed $clientSideString[, mixed $acceptLanguage = null ]) : mixed
Parameters
- $identifierOrHeaders : mixed
- $clientSideString : mixed
- $acceptLanguage : mixed = null
cachePut()
private
cachePut(mixed $identifierOrHeaders, mixed $clientSideString, mixed $properties[, mixed $acceptLanguage = null ]) : mixed
Parameters
- $identifierOrHeaders : mixed
- $clientSideString : mixed
- $properties : mixed
- $acceptLanguage : mixed = null
callFailureCallback()
Call user defined callback if set.
private
callFailureCallback(Exception $ex, $dataFile) : mixed
Parameters
checkIsDataLoaded()
private
checkIsDataLoaded() : mixed
checkReloadSchedule()
private
checkReloadSchedule(mixed $dataFile, mixed $dataFileManager[, mixed $forceReload = false ]) : mixed
Parameters
- $dataFile : mixed
- $dataFileManager : mixed
- $forceReload : mixed = false
detectProperties()
private
detectProperties(mixed $normalisedHeaders[, mixed $clientSideString = null ]) : mixed
Parameters
- $normalisedHeaders : mixed
- $clientSideString : mixed = null
extractClientSideInputs()
The client side string may contain identifiers that can be used for component detection. This method adds these identifiers to the headers map.
private
extractClientSideInputs(mixed &$dynamicProperties, mixed &$normalisedHeaders) : mixed
Parameters
- $dynamicProperties : mixed
- $normalisedHeaders : mixed
extractLanguageProperties()
private
extractLanguageProperties(mixed $properties, mixed $acceptLanguageHeader) : mixed
Parameters
- $properties : mixed
- $acceptLanguageHeader : mixed
getAcceptLanguage()
private
getAcceptLanguage(mixed $normalisedHeaders) : mixed
Parameters
- $normalisedHeaders : mixed
getDataFromFile()
private
getDataFromFile(mixed $jsonDataFilePath) : mixed
Parameters
- $jsonDataFilePath : mixed
getPropertiesFromHeaders()
private
getPropertiesFromHeaders(mixed $headers[, mixed $clientSideString = null ]) : mixed
Parameters
- $headers : mixed
- $clientSideString : mixed = null
getPropertiesFromIdentifier()
Get the properties for a User-Agent merged with the client-side properties (when provided by the DeviceAtlas client side component).
private
getPropertiesFromIdentifier(string $identifier[, mixed $clientSideString = null ]) : Properties
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.
Parameters
- $identifier : string
-
The User-Agent string
- $clientSideString : mixed = null
Tags
Return values
Properties —A set of properties (Property objects) wrapped in a Properties object
loadCachedTreeRoot()
private
loadCachedTreeRoot() : mixed
loadDataFromCache()
private
loadDataFromCache(mixed $jsonDataFilePath) : mixed
Parameters
- $jsonDataFilePath : mixed
normaliseHeaders()
Performs the following on header keys: lowercase, replaces "_" with "-" and strips prefixed "http-" if present.
private
static normaliseHeaders(mixed $headers) : mixed
Parameters
- $headers : mixed
postLoadDataInitialization()
private
postLoadDataInitialization() : mixed