Metadata.php 2.8 KB

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