Documentation

CarrierData
in package

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

Tags
copyright

Copyright (c) DeviceAtlas Limited 2023. All Rights Reserved.

author

DeviceAtlas Limited

Table of Contents

Properties

$BUCKET_START_BYTES_LEN  : mixed
bucket ID [2B], bucket CRC-32 [4B], bucket length [4B]
$copyright  : mixed
Data file copyright tag
$CREATION_DATE_LEN  : mixed
e.g. 2013-08-07T15:36:44+0000
$creationDate  : mixed
Data file creation date
$cursor  : mixed
Data cursor
$data  : mixed
Carrier data
$FILE_ID  : mixed
Data file component
$INVALID_DATA_FILE  : mixed
Error message
$MAGIC_NUMBER  : mixed
Data file component
$MAX_IPV4_BIT  : mixed
MAX_IPV4_BIT
$NULL_PTR  : mixed
Data for the IPv4 radix tree
$PROBLEM_READING_DATA_FILE  : mixed
Error message
$propertyNames  : mixed
Property Names
$propertyStringNames  : mixed
Property String Names
$ROOT_PTR  : mixed
Starting pointer
$START_BYTES_LEN  : mixed
magic number [2B] + file id [1B] + header length [2B]
$treeLefts  : mixed
Trie component
$treeProperties  : mixed
Trie component
$treeRights  : mixed
Trie component
$version  : mixed
Data file version

Methods

getCopyright()  : string
Get data file copyright.
getCreationDate()  : string
Get data file creation date.
getProperties()  : mixed
Selects a value for a given IPv4 address, traversing tree and choosing most specific value available for a given address.
getPropertyNames()  : array<string|int, mixed>
Return a list of all the property names.
getPropertyNamesAsStrings()  : string
Return a list of all the property names.
getVersion()  : string
Get data file version.
loadDataFromFile()  : mixed
Load carrier data file.
checkFileTypeGetHeaderLength()  : int
Check the first few bytes to make sure we are opening a Carrier Identification file. Also get the length of the header.
readBuckets()  : mixed
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
readHeader()  : mixed
The header of the file contains the following data:

Properties

$BUCKET_START_BYTES_LEN

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

private static mixed $BUCKET_START_BYTES_LEN = 10

Data file copyright tag

private mixed $copyright

$CREATION_DATE_LEN

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

private static mixed $CREATION_DATE_LEN = 24

$creationDate

Data file creation date

private mixed $creationDate

$FILE_ID

Data file component

private static mixed $FILE_ID = 1

$INVALID_DATA_FILE

Error message

private static mixed $INVALID_DATA_FILE = 'Invalid data file.'

$MAGIC_NUMBER

Data file component

private static mixed $MAGIC_NUMBER = 'DA'

$MAX_IPV4_BIT

MAX_IPV4_BIT

private static mixed $MAX_IPV4_BIT = 0x80000000

$NULL_PTR

Data for the IPv4 radix tree

private static mixed $NULL_PTR = -1

$PROBLEM_READING_DATA_FILE

Error message

private static mixed $PROBLEM_READING_DATA_FILE = 'Problem reading data file.'

$propertyNames

Property Names

private mixed $propertyNames = null

$propertyStringNames

Property String Names

private mixed $propertyStringNames = null

$ROOT_PTR

Starting pointer

private static mixed $ROOT_PTR = 0

$START_BYTES_LEN

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

private static mixed $START_BYTES_LEN = 5

$treeProperties

Trie component

private mixed $treeProperties

$treeRights

Trie component

private mixed $treeRights

Methods

getCopyright()

Get data file copyright.

public getCopyright() : string
Return values
string

the copyright

getCreationDate()

Get data file creation date.

public getCreationDate() : string
Return values
string

the creationDate

getProperties()

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

public getProperties(mixed $key) : mixed
Parameters
$key : mixed
Return values
mixed

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

getPropertyNames()

Return a list of all the property names.

public getPropertyNames() : array<string|int, mixed>
Return values
array<string|int, mixed>

array of property names

getPropertyNamesAsStrings()

Return a list of all the property names.

public getPropertyNamesAsStrings() : string
Return values
string

of property names

getVersion()

Get data file version.

public getVersion() : string
Return values
string

the version

loadDataFromFile()

Load carrier data file.

public loadDataFromFile(mixed $filePath) : mixed
Parameters
$filePath : mixed
Tags
throws
DataLoadingException

Thrown when the data file can not be opened

checkFileTypeGetHeaderLength()

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

private checkFileTypeGetHeaderLength(mixed $startBytes) : int
Parameters
$startBytes : mixed
Tags
throws
DataLoadingException
Return values
int

header length

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

private readBuckets() : mixed

Bucket structure:

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

Tags
throws
DataLoadingException

readHeader()

The header of the file contains the following data:

private readHeader() : mixed

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 2013 - 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

Tags
throws
DataLoadingException

        
On this page

Search results