Mobi_Mtld_DA_Device_TreeOptimized
extends Mobi_Mtld_DA_Device_Tree
in package
This class is used by the main API class and should not be used directly.
Tags
Table of Contents
- API_ID = '1'
- CACHED_JSON_HISTORY_FILE_NAME = 'da-cache-history'
- Name of the file that keeps a history of the cached data file directories.
- CACHED_JSON_INFO_FILE_NAME = 'da-cached-info'
- Name of the file that stores the cached data file's file-size and file-modification-time.
- $config : mixed
- $lookupValue : mixed
- $stockUaHeaders : mixed
- $tree : mixed
- $cachedBooleanPropertyFalse : mixed
- $cachedBooleanPropertyTrue : mixed
- $clientProps : mixed
- $dataIsLoaded : mixed
- $deviceIdPropNameId : mixed
- $jsonBatchDir : mixed
- the directory in which the json fragments are put
- $jsonTempDir : mixed
- the directory in which the the api puts it's temp and cache files
- $lookupPropType : mixed
- $lookupSource : mixed
- $MIN_JSON_VERSION : mixed
- $nicePropName : mixed
- $treeRegexes : mixed
- $uaProps : mixed
- $XMSG_CLIENT_PROPERTIES_NOT_SUPPORTED : mixed
- $XMSG_FILE_NOT_FOUND : mixed
- $XMSG_JSON_INVALID : mixed
- $XMSG_JSON_LOAD : mixed
- $XMSG_JSON_MISSING_REGEX_RULES : mixed
- $XMSG_JSON_VERSION : mixed
- $batchId : mixed
- recursive pointer
- $cacheKeySuffix : mixed
- $cacheProvider : mixed
- $cacheRootJsonFilePath : mixed
- path to the root json file 0.serialized
- $defaultLookupSource : mixed
- $jsonDataFilePath : mixed
- path to the json file passed to the api
- $MAX_CACHE_JSON_FILES : mixed
- max number of JSON files to keep in cache, older JSON files will be deleted.
- $MIN_BATCH_SIZE : mixed
- batch config
- $treeValueDict : mixed
- tree 'v' node
- $useTreeOptimizer : mixed
- __construct() : mixed
- Create the JSON tree handler.
- clearCache() : mixed
- Remove all tree optimization cache files
- getDataCreationTimestamp() : mixed
- Get data file creation timestamp
- getDataRevision() : mixed
- getDataVersion() : mixed
- Get data file version
- getLookupSource() : string
- Get the source properties fetch source to be used for debugging.
- getPropertyNames() : mixed
- Get the list of all available property names from the tree (not contains client side props)
- loadTreeFromFile() : mixed
- Load the JSON tree file into the handler.
- loadTreeFromString() : mixed
- Load the JSON tree into the handler.
- populateCache() : bool
- Break down the DeviceAtlas JSON data file into smaller files and save the batch into "/da-api-temp-dir/batch-cache-dir".
- putProperties() : mixed
- Get properties from tree walk/ua/client-side and put them in the tree.properties use cached properties if exists.
- putTreeWalkProperties() : mixed
- Get properties from tree walk/ua and put them in the tree.properties
- setConfig() : mixed
- Set new config settings via a new Config object.
- sanitizeTree() : mixed
- __loadTreeFromFile() : mixed
- __populateCache() : mixed
- for internal cache populations usages
- cacheTree() : mixed
- Break down tree and save to files.
- cleanup() : mixed
- Remove the old batches and create the new root json.
- fixValues() : mixed
- Swap value ids with values in a tree node
- getFileId() : mixed
- Get a unique identifier a json-file e.g. (filetime, filesize), to know when the file is changed
- loadCachedTreeRoot() : mixed
- try to load the root cached json file, if not exists try to load and populate the original
- rmdir() : mixed
- Recursively remove files and dirs.
- seekProperties() : mixed
- Seek properties for a user agent within a node. This is designed to be recursed, and only externally called with the node representing the top of the tree
- throwFileWrite() : mixed
- Throw a file/directory write exception
Constants
API_ID
public
mixed
API_ID
= '1'
CACHED_JSON_HISTORY_FILE_NAME
Name of the file that keeps a history of the cached data file directories.
public
mixed
CACHED_JSON_HISTORY_FILE_NAME
= 'da-cache-history'
CACHED_JSON_INFO_FILE_NAME
Name of the file that stores the cached data file's file-size and file-modification-time.
public
mixed
CACHED_JSON_INFO_FILE_NAME
= 'da-cached-info'
This info is used to sense auto data file changes.
Properties
$config
public
mixed
$config
= \null
$lookupValue
public
mixed
$lookupValue
= \true
$stockUaHeaders
public
mixed
$stockUaHeaders
= array('x-device-user-agent', 'x-original-user-agent', 'x-operamini-phone-ua', 'x-skyfire-phone', 'x-bolt-phone-ua', 'device-stock-ua', 'x-ucbrowser-ua', 'x-ucbrowser-device-ua', 'x-ucbrowser-device', 'x-puffin-ua')
$tree
public
mixed
$tree
= \null
$cachedBooleanPropertyFalse
protected
mixed
$cachedBooleanPropertyFalse
= \null
$cachedBooleanPropertyTrue
protected
mixed
$cachedBooleanPropertyTrue
= \null
$clientProps
protected
mixed
$clientProps
= \null
$dataIsLoaded
protected
mixed
$dataIsLoaded
$deviceIdPropNameId
protected
mixed
$deviceIdPropNameId
$jsonBatchDir
the directory in which the json fragments are put
protected
mixed
$jsonBatchDir
$jsonTempDir
the directory in which the the api puts it's temp and cache files
protected
mixed
$jsonTempDir
$lookupPropType
protected
mixed
$lookupPropType
= \null
$lookupSource
protected
mixed
$lookupSource
= 'tree'
$MIN_JSON_VERSION
protected
static mixed
$MIN_JSON_VERSION
= 0.7
$nicePropName
protected
mixed
$nicePropName
= \null
$treeRegexes
protected
mixed
$treeRegexes
= \null
$uaProps
protected
mixed
$uaProps
= \null
$XMSG_CLIENT_PROPERTIES_NOT_SUPPORTED
protected
static mixed
$XMSG_CLIENT_PROPERTIES_NOT_SUPPORTED
= 'JSON data does not support Client-side properties.'
$XMSG_FILE_NOT_FOUND
protected
static mixed
$XMSG_FILE_NOT_FOUND
= 'Unable to read "%s" file, make sure file exists and has read permissions.'
$XMSG_JSON_INVALID
protected
static mixed
$XMSG_JSON_INVALID
= 'Bad data loaded into the tree.'
$XMSG_JSON_LOAD
protected
static mixed
$XMSG_JSON_LOAD
= 'Unable to load JSON data.'
$XMSG_JSON_MISSING_REGEX_RULES
protected
static mixed
$XMSG_JSON_MISSING_REGEX_RULES
= 'Missing regex rules.'
$XMSG_JSON_VERSION
protected
static mixed
$XMSG_JSON_VERSION
= 'This version of the API requires a newer version of the JSON data.'
$batchId
recursive pointer
private
mixed
$batchId
$cacheKeySuffix
private
mixed
$cacheKeySuffix
$cacheProvider
private
mixed
$cacheProvider
$cacheRootJsonFilePath
path to the root json file 0.serialized
private
mixed
$cacheRootJsonFilePath
$defaultLookupSource
private
mixed
$defaultLookupSource
= 'tree'
$jsonDataFilePath
path to the json file passed to the api
private
mixed
$jsonDataFilePath
$MAX_CACHE_JSON_FILES
max number of JSON files to keep in cache, older JSON files will be deleted.
private
static mixed
$MAX_CACHE_JSON_FILES
= 2
$MIN_BATCH_SIZE
batch config
private
static mixed
$MIN_BATCH_SIZE
= 256
$treeValueDict
tree 'v' node
private
mixed
$treeValueDict
$useTreeOptimizer
private
mixed
$useTreeOptimizer
= \null
Methods
__construct()
Create the JSON tree handler.
public
__construct(mixed $config) : mixed
Parameters
- $config : mixed
Return values
mixed —clearCache()
Remove all tree optimization cache files
public
clearCache() : mixed
Return values
mixed —getDataCreationTimestamp()
Get data file creation timestamp
public
getDataCreationTimestamp() : mixed
Return values
mixed —getDataRevision()
public
getDataRevision() : mixed
Return values
mixed —getDataVersion()
Get data file version
public
getDataVersion() : mixed
Return values
mixed —getLookupSource()
Get the source properties fetch source to be used for debugging.
public
getLookupSource() : string
Return values
string —'tree' or 'optimized tree' or 'cache'
getPropertyNames()
Get the list of all available property names from the tree (not contains client side props)
public
getPropertyNames() : mixed
Return values
mixed —loadTreeFromFile()
Load the JSON tree file into the handler.
public
loadTreeFromFile(mixed $jsonDataFilePath) : mixed
Parameters
- $jsonDataFilePath : mixed
Tags
Return values
mixed —loadTreeFromString()
Load the JSON tree into the handler.
public
loadTreeFromString(mixed $json) : mixed
Parameters
- $json : mixed
Tags
Return values
mixed —populateCache()
Break down the DeviceAtlas JSON data file into smaller files and save the batch into "/da-api-temp-dir/batch-cache-dir".
public
populateCache(mixed $jsonDataFilePath[, mixed $force = false ]) : bool
Parameters
- $jsonDataFilePath : mixed
- $force : mixed = false
Return values
bool —true=populated json batch cache files
putProperties()
Get properties from tree walk/ua/client-side and put them in the tree.properties use cached properties if exists.
public
putProperties(mixed $userAgent, mixed $stockUserAgents, mixed $clientside, mixed &$properties) : mixed
Parameters
- $userAgent : mixed
- $stockUserAgents : mixed
- $clientside : mixed
- $properties : mixed
Return values
mixed —putTreeWalkProperties()
Get properties from tree walk/ua and put them in the tree.properties
public
putTreeWalkProperties(mixed $userAgent, mixed $stockUserAgents, mixed &$properties) : mixed
if stockUserAgents != null - iterate over stockUserAgents for each item: tree-walk and stop iteration if result has deviceId - use userAgent for detecting the ua-props
if stockUserAgents == null - use userAgent for tree walk - use userAgent for detecting the ua-props
Parameters
- $userAgent : mixed
- $stockUserAgents : mixed
- $properties : mixed
Return values
mixed —setConfig()
Set new config settings via a new Config object.
public
setConfig(type $config) : mixed
Parameters
- $config : type
Return values
mixed —sanitizeTree()
protected
sanitizeTree() : mixed
Tags
Return values
mixed —__loadTreeFromFile()
private
__loadTreeFromFile() : mixed
Return values
mixed —__populateCache()
for internal cache populations usages
private
__populateCache([mixed $force = true ]) : mixed
Parameters
- $force : mixed = true
Return values
mixed —cacheTree()
Break down tree and save to files.
private
cacheTree(mixed &$tree, mixed $depth) : mixed
Parameters
- $tree : mixed
- $depth : mixed
Return values
mixed —cleanup()
Remove the old batches and create the new root json.
private
cleanup() : mixed
Return values
mixed —fixValues()
Swap value ids with values in a tree node
private
fixValues(mixed &$node) : mixed
Parameters
- $node : mixed
Return values
mixed —getFileId()
Get a unique identifier a json-file e.g. (filetime, filesize), to know when the file is changed
private
static getFileId(mixed $filePath) : mixed
Parameters
- $filePath : mixed
Return values
mixed —loadCachedTreeRoot()
try to load the root cached json file, if not exists try to load and populate the original
private
loadCachedTreeRoot() : mixed
Return values
mixed —rmdir()
Recursively remove files and dirs.
private
static rmdir(mixed $dir) : mixed
Parameters
- $dir : mixed
Return values
mixed —seekProperties()
Seek properties for a user agent within a node. This is designed to be recursed, and only externally called with the node representing the top of the tree
private
seekProperties(mixed $userAgent, mixed &$properties, mixed &$props2Vals) : mixed
Parameters
- $userAgent : mixed
- $properties : mixed
- $props2Vals : mixed
Return values
mixed —throwFileWrite()
Throw a file/directory write exception
private
static throwFileWrite(mixed $path) : mixed
Parameters
- $path : mixed