Skip to content

Commit b952dce

Browse files
committed
GeoIP2 v0.9.2 PHP Extension
- ported MaxMind DB Reader
1 parent 36c23f0 commit b952dce

File tree

250 files changed

+26059
-820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+26059
-820
lines changed

README.md

+68-38
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,75 @@
1-
# PHP GeoIP2 extension #
1+
# PHP GeoIP2 extension
22

3-
## Description ##
3+
## Description
44

5-
This package provides an API for the GeoIP2
6-
[databases](http://dev.maxmind.com/geoip/geoip2/downloadable). The API also
7-
works with the free
5+
This extension provides an API for the MaxMind
6+
[GeoIP2 databases](http://dev.maxmind.com/geoip/geoip2/downloadable) and free
87
[GeoLite2 databases](http://dev.maxmind.com/geoip/geoip2/geolite2/).
98

10-
### Dependencies ###
9+
This extension is a port of the official [MaxMind GeoIP2 PHP package](https://github.com/maxmind/GeoIP2-php)
10+
and [MaxMind DB Reader PHP package](https://github.com/maxmind/MaxMind-DB-Reader-php).
11+
It is written in Zephir and converted to C.
1112

12-
This extension depends on:
13+
### Requirements
14+
15+
Since version 0.9.2 this extension requires PHP 7 or greater.
16+
17+
### Building extension
18+
19+
#### Prerequisites
20+
21+
Since version 0.9.2, gcc 7+ is required. To enable it on CentOS:
22+
23+
```
24+
yum install -y yum-utils centos-release-scl
25+
yum -y --enablerepo=centos-sclo-rh-testing install devtoolset-7-gcc
26+
echo "source /opt/rh/devtoolset-7/enable" | sudo tee -a /etc/profile
27+
source /opt/rh/devtoolset-7/enable
28+
```
29+
30+
Building with Zephir (recommended)
1331

1432
```
15-
php-maxminddb
16-
php-json
33+
zephir compile
34+
zephir install
1735
```
1836

19-
## IP Geolocation Usage ##
37+
Building without Zephir
38+
39+
```
40+
cd ext
41+
phpize
42+
./configure
43+
make
44+
make install
45+
```
46+
47+
This extension can also read custom databases created using
48+
[MaxMind DB Writer](https://github.com/maxmind/MaxMind-DB-Writer-perl]).
49+
50+
```
51+
use GeoIP2\Database\Reader;
52+
53+
$ipAddress = '8.8.8.8';
54+
$databaseFile = 'mydb.mmdb';
55+
56+
$reader = new Reader($databaseFile);
57+
58+
print_r($record = $reader->custom($ipAddress));
59+
60+
print_r($record->raw['color']);
61+
print_r($record->get('dogs'));
62+
```
63+
64+
## IP Geolocation Usage
2065

2166
IP geolocation is inherently imprecise. Locations are often near the center of
2267
the population. Any location provided by a GeoIP2 database or web service
2368
should not be used to identify a particular address or household.
2469

25-
## Database Reader ##
70+
## Database Reader
2671

27-
### Usage ###
72+
### Usage
2873

2974
To use this API, you must create a new `\GeoIP2\Database\Reader` object with
3075
the path to the database file as the first argument to the constructor. You
@@ -41,7 +86,7 @@ is thrown. If the database is invalid or corrupt, a
4186

4287
See the API documentation for more details.
4388

44-
### City Example ###
89+
### City Example
4590

4691
```php
4792
<?php
@@ -72,7 +117,7 @@ print($record->location->longitude . "\n"); // -93.2323
72117

73118
```
74119

75-
### Anonymous IP Example ###
120+
### Anonymous IP Example
76121

77122
```php
78123
<?php
@@ -90,7 +135,7 @@ print($record->ipAddress . "\n"); // '128.101.101.101'
90135

91136
```
92137

93-
### Connection-Type Example ###
138+
### Connection-Type Example
94139

95140
```php
96141
<?php
@@ -108,7 +153,7 @@ print($record->ipAddress . "\n"); // '128.101.101.101'
108153

109154
```
110155

111-
### Domain Example ###
156+
### Domain Example
112157

113158
```php
114159
<?php
@@ -126,7 +171,7 @@ print($record->ipAddress . "\n"); // '128.101.101.101'
126171

127172
```
128173

129-
### Enterprise Example ###
174+
### Enterprise Example
130175

131176
```php
132177
<?php
@@ -160,7 +205,7 @@ print($record->location->longitude . "\n"); // -93.2323
160205

161206
```
162207

163-
### ISP Example ###
208+
### ISP Example
164209

165210
```php
166211
<?php
@@ -182,7 +227,7 @@ print($record->ipAddress . "\n"); // '128.101.101.101'
182227

183228
```
184229

185-
## Values to use for Database or Array Keys ##
230+
## Values to use for Database or Array Keys
186231

187232
**We strongly discourage you from using a value from any `names` property as
188233
a key in a database or array.**
@@ -196,7 +241,7 @@ following:
196241
`$country->isoCode` or `$country->geonameId`
197242
* `GeoIP2\Record\Subdivision` - `$subdivision->isoCode` or `$subdivision->geonameId`
198243

199-
### What data is returned? ###
244+
### What data is returned?
200245

201246
While many of the end points return the same basic records, the attributes
202247
which can be populated vary between end points. In addition, while an end
@@ -213,7 +258,7 @@ for details on what data each end point may return.
213258
The only piece of data which is always returned is the `ipAddress`
214259
attribute in the `GeoIP2\Record\Traits` record.
215260

216-
## Integration with GeoNames ##
261+
## Integration with GeoNames
217262

218263
[GeoNames](http://www.geonames.org/) offers web services and downloadable
219264
databases with data on geographical features around the world, including
@@ -228,7 +273,7 @@ Some of the data that MaxMind provides is also sourced from GeoNames. We
228273
source things like place names, ISO codes, and other similar data from
229274
the GeoNames premium data set.
230275

231-
## Reporting data problems ##
276+
## Reporting data problems
232277

233278
If the problem you find is that an IP address is incorrectly mapped,
234279
please
@@ -246,26 +291,11 @@ If you are a paying MaxMind customer and you're not sure where to submit
246291
a correction, please
247292
[contact MaxMind support](http://www.maxmind.com/en/support) for help.
248293

249-
## Other Support ##
294+
## Other Support
250295

251296
Please report all issues with this code using the
252297
[GitHub issue tracker](https://github.com/php-extensions/php-geoip2/issues).
253298

254299
If you are having an issue with a MaxMind service that is not specific
255300
to the client API, please see
256301
[MaxMind support page](http://www.maxmind.com/en/support).
257-
258-
## Requirements ##
259-
260-
This library requires PHP 5.4 or greater.
261-
262-
This library also relies on the [MaxMind DB Reader](https://github.com/maxmind/MaxMind-DB-Reader-php).
263-
264-
## Contributing ##
265-
266-
Patches and pull requests are encouraged. All code should follow the PSR-2
267-
style guidelines. Please include unit tests whenever possible. You may obtain
268-
the test data for the maxmind-db folder by running `git submodule update
269-
--init --recursive` or adding `--recursive` to your initial clone, or from
270-
https://github.com/maxmind/MaxMind-DB
271-

config.json

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
2+
"namespace": "geoip2",
3+
"name": "geoip2",
4+
"description": "GeoIP2 PHP API",
5+
"author": "github.com/php-extensions",
6+
"version": "0.9.2",
7+
"verbose": false,
8+
"requires": {
9+
"extensions": []
10+
},
11+
212
"stubs": {
313
"path": "ide\/%version%\/%namespace%\/",
414
"stubs-run-after-generate": false
@@ -52,13 +62,7 @@
5262
"check-invalid-reads": false,
5363
"internal-call-transformation": false
5464
},
55-
"namespace": "geoip2",
56-
"name": "geoip2",
57-
"description": "GeoIP2 PHP API",
58-
"author": "github.com/php-extensions",
59-
"version": "0.9.1",
60-
"verbose": false,
61-
"requires": {
62-
"extensions": ["maxminddb", "json"]
63-
}
65+
66+
"extra-classes": [
67+
]
6468
}

doc/0.9.2/asset/api_definition.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/0.9.2/asset/static/jquery.min.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/0.9.2/asset/static/prettify.css

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.pln {
2+
color: rgb(184, 208, 224);
3+
}
4+
5+
.str {
6+
color: #f66;
7+
}
8+
.kwd {
9+
color: #6abafb
10+
}
11+
.com {
12+
color: #800
13+
}
14+
.typ {
15+
color: rgb(184, 208, 224);
16+
}
17+
.lit {
18+
color: #066
19+
}
20+
.pun,
21+
.opn,
22+
.clo {
23+
color: #660
24+
}
25+
.tag {
26+
color: #008
27+
}
28+
.atn {
29+
color: #606
30+
}
31+
.atv {
32+
color: #080
33+
}
34+
.dec,
35+
.var {
36+
color: #606
37+
}
38+
.fun {
39+
color: red
40+
}
41+
42+
pre.prettyprint {
43+
padding:5px;
44+
border-left: 3px solid #3E6496;
45+
background: rgb(18, 27, 33);
46+
color: #f6f3e8;
47+
word-break: break-all;
48+
font-size: 13px;
49+
font-family: Consolas, Menlo, 'Courier New', monospace;
50+
}
51+
52+
ol.linenums {
53+
margin-top: 0;
54+
margin-bottom: 0
55+
}
56+
li.L0,
57+
li.L1,
58+
li.L2,
59+
li.L3,
60+
li.L5,
61+
li.L6,
62+
li.L7,
63+
li.L8 {
64+
list-style-type: none
65+
}
66+
li.L1,
67+
li.L3,
68+
li.L5,
69+
li.L7,
70+
li.L9 {
71+
72+
}
73+
74+
75+
76+
77+
.prettyprint>ol{
78+
counter-reset: ptpcounter;
79+
}
80+
81+
.prettyprint>ol>li{
82+
position: relative;
83+
}
84+
85+
86+
.prettyprint>ol>li:before{
87+
content: counter(ptpcounter);
88+
counter-increment: ptpcounter;
89+
color: rgb(148, 148, 148);
90+
display: block;
91+
width: 33px;
92+
position: absolute;
93+
left: -44px;
94+
text-align: right;
95+
overflow: visible;
96+
}

0 commit comments

Comments
 (0)