Skip to content

Commit 48489fb

Browse files
Dan Shepherdisfedorov
authored andcommitted
Add MaxMindDb stub
1 parent 298316b commit 48489fb

File tree

2 files changed

+182
-0
lines changed

2 files changed

+182
-0
lines changed

PhpStormStubsMap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ final class PhpStormStubsMap
662662
'LuaSandboxRuntimeError' => 'LuaSandbox/LuaSandbox.php',
663663
'LuaSandboxSyntaxError' => 'LuaSandbox/LuaSandbox.php',
664664
'LuaSandboxTimeoutError' => 'LuaSandbox/LuaSandbox.php',
665+
'MaxMind\\Db\\InvalidDatabaseException' => 'maxminddb/maxminddb.php',
666+
'MaxMind\\Db\\Metadata' => 'maxminddb/maxminddb.php',
667+
'MaxMind\\Db\\Reader' => 'maxminddb/maxminddb.php',
665668
'Memcache' => 'memcache/memcache.php',
666669
'MemcachePool' => 'memcache/memcache.php',
667670
'Memcached' => 'memcached/memcached.php',

maxminddb/maxminddb.php

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<?php
2+
3+
namespace MaxMind\Db;
4+
5+
/**
6+
* Instances of this class provide a reader for the MaxMind DB format. IP
7+
* addresses can be looked up using the get method.
8+
*/
9+
class Reader
10+
{
11+
/**
12+
* Constructs a Reader for the MaxMind DB format. The file passed to it must
13+
* be a valid MaxMind DB file such as a GeoIp2 database file.
14+
*
15+
* @param string $database the MaxMind DB file to use
16+
*
17+
* @throws \InvalidArgumentException for invalid database path or unknown arguments
18+
* @throws InvalidDatabaseException
19+
* if the database is invalid or there is an error reading
20+
* from it
21+
*/
22+
public function __construct(string $database)
23+
{
24+
}
25+
26+
/**
27+
* Retrieves the record for the IP address.
28+
*
29+
* @param string $ipAddress the IP address to look up
30+
*
31+
* @return mixed the record for the IP address
32+
* @throws \InvalidArgumentException if something other than a single IP address is passed to the method
33+
* @throws InvalidDatabaseException
34+
* if the database is invalid or there is an error reading
35+
* from it
36+
*
37+
* @throws \BadMethodCallException if this method is called on a closed database
38+
*/
39+
public function get(string $ipAddress): mixed
40+
{
41+
}
42+
43+
/**
44+
* Retrieves the record for the IP address and its associated network prefix length.
45+
*
46+
* @param string $ipAddress the IP address to look up
47+
*
48+
* @return array{0:mixed, 1:int} an array where the first element is the record and the
49+
* second the network prefix length for the record
50+
* @throws \InvalidArgumentException if something other than a single IP address is passed to the method
51+
* @throws InvalidDatabaseException
52+
* if the database is invalid or there is an error reading
53+
* from it
54+
*
55+
* @throws \BadMethodCallException if this method is called on a closed database
56+
*/
57+
public function getWithPrefixLen(string $ipAddress): array
58+
{
59+
}
60+
61+
/**
62+
* @return Metadata object for the database
63+
* @throws \BadMethodCallException if the database has been closed
64+
*
65+
* @throws \InvalidArgumentException if arguments are passed to the method
66+
*/
67+
public function metadata(): Metadata
68+
{
69+
}
70+
71+
/**
72+
* Closes the MaxMind DB and returns resources to the system.
73+
*
74+
* @throws \Exception
75+
* if an I/O error occurs
76+
*/
77+
public function close(): void
78+
{
79+
}
80+
}
81+
82+
/**
83+
* This class should be thrown when unexpected data is found in the database.
84+
*/
85+
class InvalidDatabaseException extends \Exception
86+
{
87+
}
88+
89+
/**
90+
* This class provides the metadata for the MaxMind DB file.
91+
*/
92+
class Metadata
93+
{
94+
/**
95+
* This is an unsigned 16-bit integer indicating the major version number
96+
* for the database's binary format.
97+
*
98+
* @var int
99+
*/
100+
public int $binaryFormatMajorVersion;
101+
102+
/**
103+
* This is an unsigned 16-bit integer indicating the minor version number
104+
* for the database's binary format.
105+
*
106+
* @var int
107+
*/
108+
public int $binaryFormatMinorVersion;
109+
110+
/**
111+
* This is an unsigned 64-bit integer that contains the database build
112+
* timestamp as a Unix epoch value.
113+
*
114+
* @var int
115+
*/
116+
public int $buildEpoch;
117+
118+
/**
119+
* This is a string that indicates the structure of each data record
120+
* associated with an IP address. The actual definition of these
121+
* structures is left up to the database creator.
122+
*
123+
* @var string
124+
*/
125+
public string $databaseType;
126+
127+
/**
128+
* This key will always point to a map (associative array). The keys of
129+
* that map will be language codes, and the values will be a description
130+
* in that language as a UTF-8 string. May be undefined for some
131+
* databases.
132+
*
133+
* @var array<string, string>
134+
*/
135+
public array $description;
136+
137+
/**
138+
* This is an unsigned 16-bit integer which is always 4 or 6. It indicates
139+
* whether the database contains IPv4 or IPv6 address data.
140+
*
141+
* @var int
142+
*/
143+
public int $ipVersion;
144+
145+
/**
146+
* An array of strings, each of which is a language code. A given record
147+
* may contain data items that have been localized to some or all of
148+
* these languages. This may be undefined.
149+
*
150+
* @var array<string>
151+
*/
152+
public array $languages;
153+
154+
/**
155+
* @var int
156+
*/
157+
public int $nodeByteSize;
158+
159+
/**
160+
* This is an unsigned 32-bit integer indicating the number of nodes in
161+
* the search tree.
162+
*
163+
* @var int
164+
*/
165+
public int $nodeCount;
166+
167+
/**
168+
* This is an unsigned 16-bit integer. It indicates the number of bits in a
169+
* record in the search tree. Note that each node consists of two records.
170+
*
171+
* @var int
172+
*/
173+
public int $recordSize;
174+
175+
/**
176+
* @var int
177+
*/
178+
public int $searchTreeSize;
179+
}

0 commit comments

Comments
 (0)