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