Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
920a92f352 | ||
|
|
0d90c7a78e | ||
|
|
d52a0b057e | ||
|
|
5c4dd5b1e5 | ||
|
|
942ba4b8f5 | ||
|
|
a9fa7194aa | ||
|
|
13fbcae21c |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,6 +1,18 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.8.0 (2014-09-10)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
* The `GeoIP2\Database\Reader` lookup methods (e.g., `city()`, `isp()`) now
|
||||||
|
throw an `BadMethodCallException` if they are used with a database that
|
||||||
|
does not match the method. In particular, doing a `city()` lookup on a
|
||||||
|
GeoIP2 Country database will result in an exception, and vice versa.
|
||||||
|
* A `metadata()` method has been added to the `GeoIP2\Database\Reader` class.
|
||||||
|
This returns a `MaxMind\Db\Reader\Metadata` class with information about the
|
||||||
|
database.
|
||||||
|
* The name attribute was missing from the RepresentedCountry class.
|
||||||
|
|
||||||
0.7.0 (2014-07-22)
|
0.7.0 (2014-07-22)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ You should now have the file `composer.phar` in your project directory.
|
|||||||
Run in your project root:
|
Run in your project root:
|
||||||
|
|
||||||
```
|
```
|
||||||
php composer.phar require geoip2/geoip2:~0.7.0
|
php composer.phar require geoip2/geoip2:~0.8.0
|
||||||
```
|
```
|
||||||
|
|
||||||
You should now have the files `composer.json` and `composer.lock` as well as
|
You should now have the files `composer.json` and `composer.lock` as well as
|
||||||
@@ -293,6 +293,9 @@ This library works and is tested with HHVM.
|
|||||||
This library also relies on the [Guzzle HTTP client](http://guzzlephp.org/)
|
This library also relies on the [Guzzle HTTP client](http://guzzlephp.org/)
|
||||||
and the [MaxMind DB Reader](https://github.com/maxmind/MaxMind-DB-Reader-php).
|
and the [MaxMind DB Reader](https://github.com/maxmind/MaxMind-DB-Reader-php).
|
||||||
|
|
||||||
|
If you are using PHP 5.3 with an autoloader besides Composer, you must load
|
||||||
|
`JsonSerializable.php` in the `compat` directory.
|
||||||
|
|
||||||
## Contributing ##
|
## Contributing ##
|
||||||
|
|
||||||
Patches and pull requests are encouraged. All code should follow the
|
Patches and pull requests are encouraged. All code should follow the
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ if [ -n "$(git status --porcelain)" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
apigen --quiet --download --title "GeoIP2 PHP API $TAG" --source ../src --destination doc/$TAG
|
../vendor/bin/apigen --quiet --download --title "GeoIP2 PHP API $TAG" --source ../src --destination doc/$TAG
|
||||||
|
|
||||||
PAGE=index.md
|
PAGE=index.md
|
||||||
cat <<EOF > $PAGE
|
cat <<EOF > $PAGE
|
||||||
|
|||||||
@@ -14,10 +14,12 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"guzzle/guzzle": "3.*",
|
"guzzle/guzzle": "3.*",
|
||||||
"maxmind-db/reader": "~0.3.1",
|
"maxmind-db/reader": "~0.3.2",
|
||||||
"php": ">=5.3.1"
|
"php": ">=5.3.1"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"apigen/apigen": "~2.8.0",
|
||||||
|
"nette/nette": "~2.1.3",
|
||||||
"phpunit/phpunit": "4.1.*",
|
"phpunit/phpunit": "4.1.*",
|
||||||
"satooshi/php-coveralls": "dev-master"
|
"satooshi/php-coveralls": "dev-master"
|
||||||
},
|
},
|
||||||
|
|||||||
Submodule maxmind-db updated: c57c2ccf4a...1d28147617
@@ -71,7 +71,11 @@ class Reader implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function city($ipAddress)
|
public function city($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->modelFor('City', $ipAddress);
|
return $this->modelFor(
|
||||||
|
'City',
|
||||||
|
array('GeoLite2-City', 'GeoIP2-City'),
|
||||||
|
$ipAddress
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,64 +92,49 @@ class Reader implements ProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function country($ipAddress)
|
public function country($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->modelFor('Country', $ipAddress);
|
return $this->modelFor(
|
||||||
}
|
'Country',
|
||||||
|
array('GeoLite2-Country', 'GeoIP2-Country'),
|
||||||
/**
|
$ipAddress
|
||||||
* This method returns a GeoIP2 City model.
|
);
|
||||||
*
|
|
||||||
* @param string $ipAddress IPv4 or IPv6 address as a string.
|
|
||||||
*
|
|
||||||
* @return \GeoIp2\Model\City
|
|
||||||
*
|
|
||||||
* @throws \GeoIp2\Exception\AddressNotFoundException if the address is
|
|
||||||
* not in the database.
|
|
||||||
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
|
|
||||||
* is corrupt or invalid
|
|
||||||
*
|
|
||||||
* @deprecated deprecated since version 0.7.0
|
|
||||||
*/
|
|
||||||
public function cityIspOrg($ipAddress)
|
|
||||||
{
|
|
||||||
return $this->modelFor('City', $ipAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method returns a GeoIP2 Insights model.
|
|
||||||
*
|
|
||||||
* @param string $ipAddress IPv4 or IPv6 address as a string.
|
|
||||||
*
|
|
||||||
* @return \GeoIp2\Model\Insights
|
|
||||||
*
|
|
||||||
* @throws \GeoIp2\Exception\AddressNotFoundException if the address is
|
|
||||||
* not in the database.
|
|
||||||
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
|
|
||||||
* is corrupt or invalid
|
|
||||||
*
|
|
||||||
* @deprecated deprecated since version 0.7.0
|
|
||||||
*/
|
|
||||||
public function omni($ipAddress)
|
|
||||||
{
|
|
||||||
return $this->modelFor('Insights', $ipAddress);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function connectionType($ipAddress)
|
public function connectionType($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->flatModelFor('ConnectionType', $ipAddress);
|
return $this->flatModelFor(
|
||||||
|
'ConnectionType',
|
||||||
|
'GeoIP2-Connection-Type',
|
||||||
|
$ipAddress
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function domain($ipAddress)
|
public function domain($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->flatModelFor('Domain', $ipAddress);
|
return $this->flatModelFor(
|
||||||
|
'Domain',
|
||||||
|
'GeoIP2-Domain',
|
||||||
|
$ipAddress
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isp($ipAddress)
|
public function isp($ipAddress)
|
||||||
{
|
{
|
||||||
return $this->flatModelFor('Isp', $ipAddress);
|
return $this->flatModelFor(
|
||||||
|
'Isp',
|
||||||
|
'GeoIP2-ISP',
|
||||||
|
$ipAddress
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function modelFor($class, $ipAddress)
|
private function modelFor($class, $types, $ipAddress)
|
||||||
{
|
{
|
||||||
|
if (!in_array($this->metadata()->databaseType, $types)) {
|
||||||
|
$method = lcfirst($class);
|
||||||
|
throw new \BadMethodCallException(
|
||||||
|
"The $method method cannot be used to open a "
|
||||||
|
. $this->metadata()->databaseType . " database"
|
||||||
|
);
|
||||||
|
}
|
||||||
$record = $this->getRecord($ipAddress);
|
$record = $this->getRecord($ipAddress);
|
||||||
|
|
||||||
$record['traits']['ip_address'] = $ipAddress;
|
$record['traits']['ip_address'] = $ipAddress;
|
||||||
@@ -154,8 +143,16 @@ class Reader implements ProviderInterface
|
|||||||
return new $class($record, $this->locales);
|
return new $class($record, $this->locales);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function flatModelFor($class, $ipAddress)
|
private function flatModelFor($class, $type, $ipAddress)
|
||||||
{
|
{
|
||||||
|
if ($this->metadata()->databaseType !== $type) {
|
||||||
|
$method = lcfirst($class);
|
||||||
|
throw new \BadMethodCallException(
|
||||||
|
"The $method method cannot be used to open a "
|
||||||
|
. $this->metadata()->databaseType . " database"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$record = $this->getRecord($ipAddress);
|
$record = $this->getRecord($ipAddress);
|
||||||
|
|
||||||
$record['ip_address'] = $ipAddress;
|
$record['ip_address'] = $ipAddress;
|
||||||
@@ -175,6 +172,16 @@ class Reader implements ProviderInterface
|
|||||||
return $record;
|
return $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \InvalidArgumentException if arguments are passed to the method.
|
||||||
|
* @throws \BadMethodCallException if the database has been closed.
|
||||||
|
* @return \MaxMind\Db\Reader\Metadata object for the database.
|
||||||
|
*/
|
||||||
|
public function metadata()
|
||||||
|
{
|
||||||
|
return $this->dbReader->metadata();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the GeoIP2 database and returns the resources to the system.
|
* Closes the GeoIP2 database and returns the resources to the system.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -17,22 +17,4 @@ interface ProviderInterface
|
|||||||
* @return \GeoIp2\Model\City A City model for the requested IP address.
|
* @return \GeoIp2\Model\City A City model for the requested IP address.
|
||||||
*/
|
*/
|
||||||
public function city($ipAddress);
|
public function city($ipAddress);
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ipAddress
|
|
||||||
* IPv4 or IPv6 address to lookup.
|
|
||||||
* @return \GeoIp2\Model\City A City model for the requested IP address.
|
|
||||||
*
|
|
||||||
* @deprecated deprecated since version 0.7.0
|
|
||||||
*/
|
|
||||||
public function cityIspOrg($ipAddress);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ipAddress
|
|
||||||
* IPv4 or IPv6 address to lookup.
|
|
||||||
* @return \GeoIp2\Model\Insights An Insights model for the requested IP address.
|
|
||||||
*
|
|
||||||
* @deprecated deprecated since version 0.7.0
|
|
||||||
*/
|
|
||||||
public function omni($ipAddress);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class RepresentedCountry extends Country
|
|||||||
'confidence',
|
'confidence',
|
||||||
'geonameId',
|
'geonameId',
|
||||||
'isoCode',
|
'isoCode',
|
||||||
'namespace',
|
'names',
|
||||||
'type'
|
'type'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,44 +8,39 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
public function testDefaultLocale()
|
public function testDefaultLocale()
|
||||||
{
|
{
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
foreach (array('City', 'Country') as $type) {
|
||||||
// Needed for PHP 5.3
|
$reader = new Reader("maxmind-db/test-data/GeoIP2-$type-Test.mmdb");
|
||||||
$that = $this;
|
$method = lcfirst($type);
|
||||||
$this->checkAllMethods(
|
|
||||||
function ($method) use (&$that, &$reader) {
|
|
||||||
$record = $reader->$method('81.2.69.160');
|
$record = $reader->$method('81.2.69.160');
|
||||||
$that->assertEquals('United Kingdom', $record->country->name);
|
$this->assertEquals('United Kingdom', $record->country->name);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLocaleList()
|
public function testLocaleList()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
foreach (array('City', 'Country') as $type) {
|
||||||
$reader = new Reader(
|
$reader = new Reader(
|
||||||
'maxmind-db/test-data/GeoIP2-City-Test.mmdb',
|
"maxmind-db/test-data/GeoIP2-$type-Test.mmdb",
|
||||||
array('xx', 'ru', 'pt-BR', 'es', 'en')
|
array('xx', 'ru', 'pt-BR', 'es', 'en')
|
||||||
);
|
);
|
||||||
$that = $this;
|
$method = lcfirst($type);
|
||||||
$this->checkAllMethods(
|
|
||||||
function ($method) use (&$that, &$reader) {
|
|
||||||
$record = $reader->$method('81.2.69.160');
|
$record = $reader->$method('81.2.69.160');
|
||||||
$that->assertEquals('Великобритания', $record->country->name);
|
$this->assertEquals('Великобритания', $record->country->name);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasIpAddress()
|
public function testHasIpAddress()
|
||||||
{
|
{
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
foreach (array('City', 'Country') as $type) {
|
||||||
$that = $this;
|
$reader = new Reader("maxmind-db/test-data/GeoIP2-$type-Test.mmdb");
|
||||||
$this->checkAllMethods(
|
$method = lcfirst($type);
|
||||||
function ($method) use (&$that, &$reader) {
|
|
||||||
$record = $reader->$method('81.2.69.160');
|
$record = $reader->$method('81.2.69.160');
|
||||||
$that->assertEquals('81.2.69.160', $record->traits->ipAddress);
|
$this->assertEquals('81.2.69.160', $record->traits->ipAddress);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +55,28 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException BadMethodCallException
|
||||||
|
* @expectedExceptionMessage The country method cannot be used to open a GeoIP2-City database
|
||||||
|
*/
|
||||||
|
public function testIncorrectDatabase()
|
||||||
|
{
|
||||||
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
||||||
|
$reader->country('10.10.10.10');
|
||||||
|
$reader->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException BadMethodCallException
|
||||||
|
* @expectedExceptionMessage The domain method cannot be used to open a GeoIP2-City database
|
||||||
|
*/
|
||||||
|
public function testIncorrectDatabaseFlat()
|
||||||
|
{
|
||||||
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
||||||
|
$reader->domain('10.10.10.10');
|
||||||
|
$reader->close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
* @expectedExceptionMessage is not a valid IP address
|
* @expectedExceptionMessage is not a valid IP address
|
||||||
@@ -71,6 +88,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testConnectionType()
|
public function testConnectionType()
|
||||||
{
|
{
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-Connection-Type-Test.mmdb');
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-Connection-Type-Test.mmdb');
|
||||||
@@ -112,10 +130,11 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkAllMethods($testCb)
|
public function testMetadata()
|
||||||
{
|
{
|
||||||
foreach (array('city', 'cityIspOrg', 'country', 'omni') as $method) {
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
||||||
$testCb($method);
|
$this->assertEquals('GeoIP2-City', $reader->metadata()->databaseType);
|
||||||
}
|
|
||||||
|
$reader->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user