MIN_DATA_VERSION
MIN_DATA_VERSION = 3.0
Parses the data from the JSON file.
__construct( $data)
$data |
parse() : \DeviceAtlas\Device\DeviceData
Parse and prepare the device data from the JSON.
{ "$": [object] $==Meta data [mandatory] "p": [array] p==Property names [mandatory] "v": [array] v==Values [mandatory] "d": [array] d==Codepoint delimiters [mandatory] "t": [array] t==Component Types [mandatory] "e": [array] e==Dynamic value extractors [optional] "cg": [array] cg==Constraint Groups [optional] "c": [array] c==Components [mandatory] "tr":[Object] tr==Token Trie [mandatory] "i": [array] i==Inputs [mandatory] }
IMPORTANT: The above keys are ordered by the JSON Generator to be in a predictable and optimal order. This is helpful as certain objects are required by other objects which are loaded later.
getDataTypeId( $type)
Get data type id by data type character from JSON "s", "b", "i".
$type |
getMetaData() : \DeviceAtlas\Device\MetaData
Parse the file meta data.
"$": { "version": string File Version [mandatory] "copyright": string "created": string File generation date/time ISO8601 [mandatory] "case": string Case==The character casing of the file [optional] }
getPropertiesAsPropertyNameObjects() : array
Get the Property Names. Note the order of the names is critical. They are referenced by index in other parts of the data file.
The property names are found in an array with the following structure [ { "n": string n==Property Name [mandatory] "t": char t==Property Type [mandatory] }, {...}, {...}, ... ]
getPropertyNames()
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
getPropertyDataTypes()
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
getPropertyName( $jsonPropertyNames) : \DeviceAtlas\PropertyName
Get an individual property name from the following stucture:
{ "n": string n==Property Name [mandatory] "t": char-string t==Property Type [mandatory] }
$jsonPropertyNames |
getCodePointDelimiters() : \DeviceAtlas\Device\DelimitersHandler
The delimiter codepoints are an array of integers.
[1,5,12,41... etc]
getComponentTypes() : array
The component types is an array of component type objects. Example structure:
[ { "i": short, i==Component Type ID "a": string, a==Single char name abbreviation (e.g. b=browser, a=app etc) "l": integer, l==Component type level "w": integer w==Component type weight }, .... ]
All fields are mandatory.
extractComponents() : array<mixed,array>
Extracts the components. A Component may reference parent or inheritFrom Components. To handle this, all components are loaded and the component index for the parent and inheritFrom is recorded. A second pass over the components converts the index into an actual component.
The components have the following structure:
[ {component object}, {component object}, ... {component object} ]
The index of each Component in the array is very important. It is used as a lookup to get a Component when creating the Token Trie and other objects.
getComponent( $componentIndex, $jsonComponent)
$componentIndex | ||
$jsonComponent |
checkComponent( $componentIndex, $jsonComponent)
$componentIndex | ||
$jsonComponent |
getComponentPropertyValues( $jsonComponentPropertyValue) : array
Gets the property/values for a component. The returned Map uses the property name ID as the key. The property/values have the following structure:
{ "integer-string":integer, ==> "propertyNameId":propertyValueId ... "integer-string":integer }
$jsonComponentPropertyValue |
getPropertyValue( $valueIndex, $dataTypeId)
$valueIndex | ||
$dataTypeId |
getComponentDynamicProperties(array $jsonComponentDynamicProperties) : array
The Dynamic Properties for a component is a Map of property name ID to an array of DynamicValues. Each Dynamic Value defines a component that must exist before the dynamic value and the dynamic value extractor.
have the following structure:
{ "integer-string": [array of objects], ==> "propertyNameId": [{dynamicValueObj}] ..... "integer-string": [] }
array | $jsonComponentDynamicProperties |
of Property Name ID to DynamicValue[]
getComponentDynamicValuesArray( $jsonComponentDynamicValuesArray) : array
A component may have properties that are populated dynamically at runtime.
Each dynamic property may have one or more dynamic value extractors associated to it. This is to handle the case where there may be multiple possible values present. The order of the extractors defines the priority. For example,
User-Agent: Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.9.168 Version/11.50
Property Name: browserVersion ==> the version string may be present either after "Opera" or after "Version" if the "Version" token is present. The property therefore needs two dynamic value extractors associated with it.
extractor 1: value after Opera
extractor 2: value after Version (if it is present)
The dynamic values for a given property within a component have the following structure:
"prop_name_id": [{"i":integer, i==Index of Component preceding a dynamic value [mandatory] "e":integer e==Index of Dynamic Value Extractor [mandatory] }, ...]
$jsonComponentDynamicValuesArray |
getComponentDynamicValue( $jsonComponentDynamicValues) : \DeviceAtlas\Device\DynamicValue
Get the DynamicValue object. This has the structure of:
{ "i":integer, i==Index of Component preceding a dynamic value "e":integer e==Index of Dynamic Value Extractor }
$jsonComponentDynamicValues |
getVersionedSpecificChildren( $componentIndex, $jsonComponentVersionSpecificChildren) : \DeviceAtlas\Device\VersionSpecificChildren
Extract the version-specific children:
"vc": { "p": integer (p == property name id [mandatory]) "m": integer, (m == max version parts [mandatory]) "c": [ordered array], (c == version-specific child components [optional] ) }
$componentIndex | ||
$jsonComponentVersionSpecificChildren |
extractRootInputs() : \DeviceAtlas\Device\Inputs
Extracts the inputs that are used for device detection. The inputs consists of a set of identifiers and property mappings:
"i": { (i == inputs [root level] [mandatory]) "l": [array of objects], (l == input list [mandatory]) "id": [array of objects], (id == identifiers by component type[mandatory]) "pm": [array of objects] (p == property mappings [mandatory]) }
extractInputs( $jsonInputsList) : array
Extracts the ordered list of inputs to use for Token Detection.
This has the structure:
"l": [ (l == identifier list) { (index== 0, referenced by other objects) "n": string, (n == identifier key [mandatory]) "s": string, (s == source(s) h==HTTP, c==Client side JS [mandatory]) "q": boolean, (q == if true, ensure source value is CH double quoted. },
$jsonInputsList |
extractInput( $jsonInput)
$jsonInput |
extractIdentifiersByComponentType( $inputs, $jsonInputsIdentifiersByComponentTypes)
Extract an ordered list of identifiers by component type:
"id": [ { (id == identifiers by type) "t": integer, (t == component type index [mandatory]) "i":[integer array], (i == input indexes [mandatory]) "o":[{input-object}] (o == ordered inputs [mandatory]) }, … more identifier by type objects ]
$inputs | ||
$jsonInputsIdentifiersByComponentTypes |
extractIdentifierByComponentType( $inputs, $identifiersByComponentType, $jsonInputsIdentifier)
$inputs | ||
$identifiersByComponentType | ||
$jsonInputsIdentifier |
getDependentIdentifiers( $inputs, $jsonDependentIdentifiers)
Extracts the array of dependent identifiers:
"o":[ (o == ordered inputs [mandatory])
{
"i": integer, (i == identifier input index [mandatory])
"a": [integer array] (a == associated inputs [optional])
},
… more input objects …
],
$inputs | ||
$jsonDependentIdentifiers |
getDependentIdentifier( $inputs, $jsonDependentIdentifier)
$inputs | ||
$jsonDependentIdentifier |
extractPropertyMappings( $inputs, $jsonInputsPropertyMappings)
Extracts an array of property mapping objects to assign identifier values to DeviceAtlas properties.
"pm": [ (p == property mappings) { "integer": (key is the DA property name id [mandatory]) [ (array of sources for this DA property) {"i":integer, (i == input index (from above) [mandatory]) // one of: "tt":{ (tr == trim transformation) [optional]) "b":string, (b == before characters to remove) "a":string, (a == after characters to remove) }
// or:
"ct":{[ (ct == comparison transformation) [optional])
"o":"string", (o == operator, e.g. “=” or “!=”)
"c":"string", (c == comparison value, e.g. “?1”)
"r":integer (r == return value, index into value array)
},
… optionally more comparisons
]
},
"v":{ (v == validation [optional])
"l":integer, (l == max length validation [optional])
"n":{ (n == numeric string validation [optional])
"s":"char", (s == separator character [optional])
"n":integer, (n == min count of separators [mandatory])
"x":integer, (x == max count of separators [mandatory])
}
}
]}
… optionally more sources for this DA property
},
… more property mapping objects
]
$inputs | ||
$jsonInputsPropertyMappings |
extractPropertyMappingSources( $inputs, $propertyDataTypeId, $jsonPropertyMappingSources)
$inputs | ||
$propertyDataTypeId | ||
$jsonPropertyMappingSources |
extractPropertyMappingSource( $inputs, $propertyDataTypeId, $jsonPropertyMappingSource)
$inputs | ||
$propertyDataTypeId | ||
$jsonPropertyMappingSource |
extractTrimTransformer( $jsonInputsPropertyMappingsTrimTransformation)
$jsonInputsPropertyMappingsTrimTransformation |
extractComparisonTransformers( $propertyDataTypeId, $jsonInputsPropertyMappingsComparisonTransformation)
$propertyDataTypeId | ||
$jsonInputsPropertyMappingsComparisonTransformation |
extractComparisonTransformer( $propertyDataTypeId, $jsonComparisonTransformer)
$propertyDataTypeId | ||
$jsonComparisonTransformer |
extractPropertyMappingValidator( $jsonPropertyMappingValidator)
$jsonPropertyMappingValidator |
extractPropertyMappingNumericValidator( $jsonPropertyMappingValidatorNumericString)
$jsonPropertyMappingValidatorNumericString |
getConstraintGroups() : array
Get the (optional) list of Constraint Groups. A match candidate that has a Constraint Group references it via the list index.
[ {Constraint Group object}, {Constraint Group object}, ... {Constraint Group object} ]
getConstraintGroup( $jsonConstraintGroup)
[ Match Constraint (array of Lookaround Constraints), Match Constraint, .
.. ...More match constraint ]
$jsonConstraintGroup |
getMatchConstraint( $jsonMatchConstraint)
{ "l": [ (l == Lookaround Constraint [optional]) { "i": 0, (i == To Find Component Index [mandatory]) "n": 0, (n == Min Offset [mandatory]) "x": 0 (x == Max Offset [mandatory]) }, .
..more lookaround constraints ] }
$jsonMatchConstraint |
getTokenTrie()
Extract the Token Trie that is used for matching the tokens of incoming identifiers and returning matched components.
The Token Trie is a deeply nested collection of objects. It is more efficient to use a custom parser than rely on the generic getObject() method of the JSON tokeniser class as it would create a lot of temporary objects that would just be discarded.
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 1275traverse( $parentNode) :
Traverse the JSON structure and create the Trie of Nodes for the token start and direct child nodes.
{ "t": {nodes...}, t==Token Start Child [mandatory] "c": {nodes...}, c==Direct Child [mandatory] "m": [match candidates] m==Match Candidates [mandatory] }
See the Node class for further details on Token Start and Direct child nodes.
$parentNode |
getMatchCandidates( $jsonMatchCandidates) : array|null
Get the Match Candidates for token match in the Trie. This has the structure:
[ {match candidate}, {match candidate}, ... {match candidate}, ]
$jsonMatchCandidates |
getMatchCandidate( $jsonMatchCandidates) : \DeviceAtlas\Device\MatchCandidate
A match candidate has the following structure:
{ "i": integer, i==Component Index [mandatory] "t": "eq"|"sw", r==Match Type (defaults to EQUALS if missing) [optional] "ct": {constraints} ct==Constraints (see constraints section) [optional] "g": integer g==Constraint Group Index [optional] }
$jsonMatchCandidates |
getConstraints( $jsonMatchCandidateMatchConstraint) : array
Get the match candidate constraints. Constraints have the following structure.
Either one or both constraints will be set if constraints exist for a match candidate.
{ "p":{object}, p==Position Constraint [optional] "l":[array] l==Lookaround Constraints [optional] "g":integer g=Constraint Group index [optional] }
$jsonMatchCandidateMatchConstraint |
getPositionConstraint( $jsonPositionConstraint) :
The position constraint with structure:
{ "n":integer, n==Min position (positive integer) [mandatory] "x":integer x==Max position (positive integer) [mandatory] }
$jsonPositionConstraint |
getLookaroundConstraint( $jsonLookaroundConstraint) : \DeviceAtlas\Device\LookaroundConstraint
Gets a LookaroundConstraint object. These have the following structure:
{ "i": integer, i==To Find Component Index [mandatory] "n": integer, n==Min offset (positive or negative integer) [mandatory] "x": integer x==Max offset (positive or negative integer) [mandatory] },
$jsonLookaroundConstraint |
getDynamicValueExtractors() : array
Get the dynamic value extractors. This is an array of unique extractors with the structure:
[ {Dynamic value object}, ... ]
Each Dynamic Value extractor has three possible forms with a common extractor type field in each:
{ "t":"s|v|r", t==Extractor Type ...other fields... }
The "other" fields depend on the type as follows:
"String" type: { "t":"s", t==Extractor Type, s==String Type [mandatory] "db":[integer array], db==Delimiters before (codepoints) [optional] "da":[integer array] da==Delimiters after (codepoints) [optional] }
"Version" type: { "t":"v", t==Extractor Type, s==Version Type [mandatory] "db": [integer array], db==Delimiters before (codepoints) [optional] "p": "string", p==Version Prefix [optional] "k": true|false, k==Keep Prefix [optional] "ds":"char", ds==Decimal Separator [mandatory] "a": true|false, a==Suffix Allowed [mandatory] "ss":"char", ss==Suffix Separator [optional] "da":[integer array] da==Delimiters after (codepoints) [optional] }
"Regex" type: { "t":"r", t==Extractor Type, s==Regex Type [mandatory] "d":"regex string", d==Default Regex [mandatory] "o":{"API_ID":"override regex} o==API Specific Regex override [optional] }
getPropertyConstraints( $jsonPropertyConstraints) : array
Extracts the property constraints for a match candidate.
The property constraints have the following structure:
[ {property constraints rule object 1}, {property constraints rule object 2}, … {property constraints rule object n} ]
$jsonPropertyConstraints |
getPropertyConstraint( $jsonPropertyConstraint) : \DeviceAtlas\Device\PropertyConstraint
Each property constraint is comprised of the following:
{ (Property Constraint object)
"s": ["string"] (s == source [optional])
"c": [ (c == array of comparison properties [mandatory])
{comparison property},
...More comparison properties ...
]
}
$jsonPropertyConstraint |
getComparisonProperties( $jsonComparisonProperties)
A comparison property is comprised of a property/value pair and an operator.
{ "p": integer, (p == property name id [mandatory]) "o": "string", (o == operator [mandatory]) "v": integer, (v == value id [mandatory]) "c": "string", (c == compare as [mandatory]) }
$jsonComparisonProperties |
getComparisonProperty( $jsonComparisonProperty)
$jsonComparisonProperty |
getComponentTypeById( $componentTypeId)
$componentTypeId |
getAdditionalActions( $jsonAdditionalActions)
Extracts the match constraints additional actions
{ "r": { (r == to remove/replace [optional]) "numeric-string": integer|null, (key=component type id, value=component idx or null) ... component type/components } }
$jsonAdditionalActions |
getComponentsToReplace( $jsonComponentTypesToRemove)
$jsonComponentTypesToRemove |