public function Reader::__construct in Smart IP 6.2
Same name in this branch
- 6.2 includes/vendor/geoip2/geoip2/src/Database/Reader.php \GeoIp2\Database\Reader::__construct()
- 6.2 includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php \MaxMind\Db\Reader::__construct()
Same name and namespace in other branches
- 7.2 includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader.php \MaxMind\Db\Reader::__construct()
Constructs a Reader for the MaxMind DB format. The file passed to it must be a valid MaxMind DB file such as a GeoIp2 database file.
Parameters
string $database: the MaxMind DB file to use.
Throws
\InvalidArgumentException for invalid database path or unknown arguments
\MaxMind\Db\Reader\InvalidDatabaseException if the database is invalid or there is an error reading from it.
File
- includes/
vendor/ maxmind-db/ reader/ src/ MaxMind/ Db/ Reader.php, line 37
Class
- Reader
- Instances of this class provide a reader for the MaxMind DB format. IP addresses can be looked up using the <code>get</code> method.
Namespace
MaxMind\DbCode
public function __construct($database) {
if (func_num_args() != 1) {
throw new \InvalidArgumentException('The constructor takes exactly one argument.');
}
if (!is_readable($database)) {
throw new \InvalidArgumentException("The file \"{$database}\" does not exist or is not readable.");
}
$this->fileHandle = @fopen($database, 'rb');
if ($this->fileHandle === false) {
throw new \InvalidArgumentException("Error opening \"{$database}\".");
}
$this->fileSize = @filesize($database);
if ($this->fileSize === false) {
throw new \UnexpectedValueException("Error determining the size of \"{$database}\".");
}
$start = $this
->findMetadataStart($database);
$metadataDecoder = new Decoder($this->fileHandle, $start);
list($metadataArray) = $metadataDecoder
->decode($start);
$this->metadata = new Metadata($metadataArray);
$this->decoder = new Decoder($this->fileHandle, $this->metadata->searchTreeSize + self::$DATA_SECTION_SEPARATOR_SIZE);
}