API_VERSION
API_VERSION = '1.2.1'
Carrier API version
The main class for the Carrier Identification API. Used to load the data file and to perform lookups using IPv4 addresses. For usage in a Web App it is recommended to use the CarrierApiWeb (CarrierApiWeb.php) class so you don't have to pass the client's IP address manually.
Please note that it is advisable to load only a single instance of this class to avoid multiple loadings of the data file.
Example usage:
$ip = '62.40.34.220'; $carrierApi = new CarrierApi(); $carrierApi->loadDataFromFile('/path/to/sample.dat'); // get all properties $props = $carrierApi->getProperties($ip); // .... use the properties .... if ($props->containsKey('networkOperator')) { $property = $props->get('networkOperator'); $operatorName = $property->asString(); print('networkOperator: ' . $operatorName); } // get a single property $mccProp = $carrierApi->getProperty($ip, 'mcc'); if ($mccProp !== null) { $mcc = $mccProp->asString(); print('MCC: ' . $mcc); }
Please see the code in the Examples directory for additional samples.
buildDataFile( $dataFileDownloadUrl)
$dataFileDownloadUrl |
downloadAndLoadDataFileFromUrl( $dataFile, $dataFileManager = null)
Load the DeviceAtlas data file data from a URL.
Schedule a reload if data file is stale. Re-download data file if local data file is corrupted.
$dataFile | ||
$dataFileManager |
when there is a problem downloading or loading the data file.
scheduleReloadAndFinishRequest( $dataFile, $dataFileManager)
A secondary register_shutdown_call to make sure the reload method is called as the last one.
$dataFile | ||
$dataFileManager |
reload( $dataFile, $dataFileManager, $isScheduled = false)
Downloads a new data file if the existing one is stale.
Loads data file into API.
$dataFile | ||
$dataFileManager | ||
$isScheduled |
getDataFileCopyright() : string
Returns the data file copyright text.
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 1275the copyright
getDataFileCreationDate() : string
Returns the data file creation date in ISO8601 format.
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 1275the creationDate
getDataFileVersion() : string
Returns the version of the data file.
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 1275the version
getProperties( $ipv4) : \DeviceAtlas\Properties
$ipv4 |
The found properties or null of no properties found.
getProperty( $ipv4, $propertyName) : \DeviceAtlas\Property
$ipv4 | ||
$propertyName |
Thrown if the property name does not exist.
Thrown if the property name does not exist.
The Property or null if no property found.
getPropertyNames() : array
A set of all the possible property names. The Set contains PropertyName objects that each have a name and an associated data type.
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 1275array of possible property names.
getIp( $keyVals) : string
Get the most suitable IP address from the given keyVals set of HTTP headers. This function checks the headers defined in HEADERS_TO_CHECK.
$keyVals |
The most suitable IP or NULL if a suitable IP could not be found.
isPublicIp( $ip) : boolean
An IP address is considered public if it is not in any of the following ranges: <pre> 1) any local address IP: 0
2) a local loopback address range: 127/8
3) a site local address i.e. IP is in any of the ranges: range: 10/8 range: 172.16/12 range: 192.168/16
4) a link local address range: 169.254/16
$ip |
True if it is a public IP, false if the IP is invalid or is not public.
downloadAndLoadDataFile( $dataFileDownloadUrl)
$dataFileDownloadUrl |
getDeviceAtlasApiVersion()
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
dataLoaded()
Check if the given propertyName is not null and exists in the data file.
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 1275extractIp( $headerName, $headerValue)
Extracts and cleans an IP address from the headerValue. Some headers such as "X-Forwarded-For" can contain multiple IP addresses such as: clientIP, proxy1, proxy2.
..
This method splits up the headerValue and takes the most appropriate value as the IP.
$headerName | ||
$headerValue |
checkReloadSchedule( $dataFile, $dataFileManager, $forceReload = false)
$dataFile | ||
$dataFileManager | ||
$forceReload |
callFailureCallback(\Exception $ex, $dataFile)
Call user defined callback if set.
\Exception | $ex | |
$dataFile |