\Mobi_Mtld_DA_Carrier_CarrierData

This class is responsible for loading the data file and walking the IPV4 Radix Trie to find the properties for a given User-Agent.

Summary

Methods
Properties
Constants
loadDataFromFile()
getProperties()
getPropertyNames()
getPropertyNamesAsStrings()
getCopyright()
getCreationDate()
getVersion()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
readHeader()
checkFileTypeGetHeaderLength()
readBuckets()
$MAGIC_NUMBER
$FILE_ID
$START_BYTES_LEN
$CREATION_DATE_LEN
$BUCKET_START_BYTES_LEN
$copyright
$creationDate
$version
$cursor
$NULL_PTR
$ROOT_PTR
$MAX_IPV4_BIT
$treeLefts
$treeRights
$treeProperties
$propertyNames
$propertyStringNames
$PROBLEM_READING_DATA_FILE
$INVALID_DATA_FILE
$data
N/A

Properties

$MAGIC_NUMBER

$MAGIC_NUMBER : 

Data file component

Type

$FILE_ID

$FILE_ID : 

Data file component

Type

$START_BYTES_LEN

$START_BYTES_LEN : 

magic number [2B] + file id [1B] + header length [2B]

Type

$CREATION_DATE_LEN

$CREATION_DATE_LEN : 

e.g. 2013-08-07T15:36:44+0000

Type

$BUCKET_START_BYTES_LEN

$BUCKET_START_BYTES_LEN : 

bucket ID [2B], bucket CRC-32 [4B], bucket length [4B]

Type

$copyright

$copyright : 

Data file copyright tag

Type

$creationDate

$creationDate : 

Data file creation date

Type

$version

$version : 

Data file version

Type

$cursor

$cursor : 

Data cursor

Type

$NULL_PTR

$NULL_PTR : 

Data for the IPv4 radix tree

Type

$ROOT_PTR

$ROOT_PTR : 

Starting pointer

Type

$MAX_IPV4_BIT

$MAX_IPV4_BIT : 

MAX_IPV4_BIT

Type

$treeLefts

$treeLefts : 

Trie component

Type

$treeRights

$treeRights : 

Trie component

Type

$treeProperties

$treeProperties : 

Trie component

Type

$propertyNames

$propertyNames : 

Property Names

Type

$propertyStringNames

$propertyStringNames : 

Property String Names

Type

$PROBLEM_READING_DATA_FILE

$PROBLEM_READING_DATA_FILE : 

Error message

Type

$INVALID_DATA_FILE

$INVALID_DATA_FILE : 

Error message

Type

$data

$data : 

Carrier data

Type

Methods

loadDataFromFile()

loadDataFromFile(  $filePath) 

Load carrier data file.

Parameters

$filePath

Throws

\Mobi_Mtld_DA_Exception_DataFileException

Thrown when the data file can not be opened

getProperties()

getProperties(  $key) : mixed

Selects a value for a given IPv4 address, traversing tree and choosing most specific value available for a given address.

Parameters

$key
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

Returns

mixed —

value at most specific IPv4 network in a tree for a given IPv4 address

getPropertyNames()

getPropertyNames() : array

Return a list of all the property names.

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

Returns

array —

array of property names

getPropertyNamesAsStrings()

getPropertyNamesAsStrings() : string

Return a list of all the property names.

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

Returns

string —

of property names

getCopyright()

getCopyright() : string

Get data file copyright.

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

Returns

string —

the copyright

getCreationDate()

getCreationDate() : string

Get data file creation date.

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

Returns

string —

the creationDate

getVersion()

getVersion() : string

Get data file version.

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

Returns

string —

the version

readHeader()

readHeader() 

The header of the file contains the following data:

2B DA (US-ASCII) 1B File type ID (1: carrier data, 2:some other data.... etc) 2B Header length - the total size of the header including the preceding bytes 2B Length of copyright text ?B Copyright (US-ASCII) "(c) Copyright 2021 - DeviceAtlas Limited" 24B Creation date (US-ASCII) "2013-08-07T15:36:44+0000" 1B Version, major 1B Version, minor 4B Licence ID 4B CRC-32 - all data after first bucket offset

Throws

\IOException
\EOFException
\Mobi_Mtld_DA_Exception_DataFileException

checkFileTypeGetHeaderLength()

checkFileTypeGetHeaderLength(  $startBytes) : integer

Check the first few bytes to make sure we are opening a Carrier Identification file. Also get the length of the header.

Parameters

$startBytes

Throws

\Mobi_Mtld_DA_Exception_DataFileException

Returns

integer —

header length

readBuckets()

readBuckets() 

Each bucket is comprised of the following. The BucketHandler is responsible for actually parsing the data in each bucket. This method keeps reading until either the end of the file or until all necessary buckets have been read. It will skip buckets with IDs it does not recognise to hopefully future proof the API against possible additions to the data file

Bucket structure:

2B Bucket ID 4B CRC-32 checksum - NOTE: unsigned int! 4B Length of the data ?B Data

Throws

\IOException
\EOFException
\Mobi_Mtld_DA_Exception_DataFileException