Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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