Decoder.php
2 years ago
InvalidDatabaseException.php
2 years ago
Metadata.php
2 years ago
Util.php
2 years ago
Metadata.php
106 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace IAWP_SCOPED\MaxMind\Db\Reader; |
| 5 | |
| 6 | use ArgumentCountError; |
| 7 | /** |
| 8 | * This class provides the metadata for the MaxMind DB file. |
| 9 | * @internal |
| 10 | */ |
| 11 | class Metadata |
| 12 | { |
| 13 | /** |
| 14 | * This is an unsigned 16-bit integer indicating the major version number |
| 15 | * for the database's binary format. |
| 16 | * |
| 17 | * @var int |
| 18 | */ |
| 19 | public $binaryFormatMajorVersion; |
| 20 | /** |
| 21 | * This is an unsigned 16-bit integer indicating the minor version number |
| 22 | * for the database's binary format. |
| 23 | * |
| 24 | * @var int |
| 25 | */ |
| 26 | public $binaryFormatMinorVersion; |
| 27 | /** |
| 28 | * This is an unsigned 64-bit integer that contains the database build |
| 29 | * timestamp as a Unix epoch value. |
| 30 | * |
| 31 | * @var int |
| 32 | */ |
| 33 | public $buildEpoch; |
| 34 | /** |
| 35 | * This is a string that indicates the structure of each data record |
| 36 | * associated with an IP address. The actual definition of these |
| 37 | * structures is left up to the database creator. |
| 38 | * |
| 39 | * @var string |
| 40 | */ |
| 41 | public $databaseType; |
| 42 | /** |
| 43 | * This key will always point to a map (associative array). The keys of |
| 44 | * that map will be language codes, and the values will be a description |
| 45 | * in that language as a UTF-8 string. May be undefined for some |
| 46 | * databases. |
| 47 | * |
| 48 | * @var array |
| 49 | */ |
| 50 | public $description; |
| 51 | /** |
| 52 | * This is an unsigned 16-bit integer which is always 4 or 6. It indicates |
| 53 | * whether the database contains IPv4 or IPv6 address data. |
| 54 | * |
| 55 | * @var int |
| 56 | */ |
| 57 | public $ipVersion; |
| 58 | /** |
| 59 | * An array of strings, each of which is a language code. A given record |
| 60 | * may contain data items that have been localized to some or all of |
| 61 | * these languages. This may be undefined. |
| 62 | * |
| 63 | * @var array |
| 64 | */ |
| 65 | public $languages; |
| 66 | /** |
| 67 | * @var int |
| 68 | */ |
| 69 | public $nodeByteSize; |
| 70 | /** |
| 71 | * This is an unsigned 32-bit integer indicating the number of nodes in |
| 72 | * the search tree. |
| 73 | * |
| 74 | * @var int |
| 75 | */ |
| 76 | public $nodeCount; |
| 77 | /** |
| 78 | * This is an unsigned 16-bit integer. It indicates the number of bits in a |
| 79 | * record in the search tree. Note that each node consists of two records. |
| 80 | * |
| 81 | * @var int |
| 82 | */ |
| 83 | public $recordSize; |
| 84 | /** |
| 85 | * @var int |
| 86 | */ |
| 87 | public $searchTreeSize; |
| 88 | public function __construct(array $metadata) |
| 89 | { |
| 90 | if (\func_num_args() !== 1) { |
| 91 | throw new ArgumentCountError(\sprintf('%s() expects exactly 1 parameter, %d given', __METHOD__, \func_num_args())); |
| 92 | } |
| 93 | $this->binaryFormatMajorVersion = $metadata['binary_format_major_version']; |
| 94 | $this->binaryFormatMinorVersion = $metadata['binary_format_minor_version']; |
| 95 | $this->buildEpoch = $metadata['build_epoch']; |
| 96 | $this->databaseType = $metadata['database_type']; |
| 97 | $this->languages = $metadata['languages']; |
| 98 | $this->description = $metadata['description']; |
| 99 | $this->ipVersion = $metadata['ip_version']; |
| 100 | $this->nodeCount = $metadata['node_count']; |
| 101 | $this->recordSize = $metadata['record_size']; |
| 102 | $this->nodeByteSize = $this->recordSize / 4; |
| 103 | $this->searchTreeSize = $this->nodeCount * $this->nodeByteSize; |
| 104 | } |
| 105 | } |
| 106 |