Compare commits
No commits in common. "master" and "v2.1.1" have entirely different histories.
@ -305,7 +305,7 @@ supported.
|
|||||||
|
|
||||||
This library works and is tested with HHVM.
|
This library works and is tested with HHVM.
|
||||||
|
|
||||||
This library also relies on the [Guzzle3 HTTP client](https://github.com/guzzle/guzzle3)
|
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
|
If you are using PHP 5.3 with an autoloader besides Composer, you must load
|
||||||
@ -314,7 +314,7 @@ If you are using PHP 5.3 with an autoloader besides Composer, you must load
|
|||||||
## Contributing ##
|
## Contributing ##
|
||||||
|
|
||||||
Patches and pull requests are encouraged. All code should follow the
|
Patches and pull requests are encouraged. All code should follow the
|
||||||
PSR-2 style guidelines. Please include unit tests whenever possible. You may obtain the test data for the maxmind-db folder by running `git submodule update --init --recursive` or adding `--recursive` to your initial clone, or from https://github.com/maxmind/MaxMind-DB
|
PSR-2 style guidelines. Please include unit tests whenever possible.
|
||||||
|
|
||||||
## Versioning ##
|
## Versioning ##
|
||||||
|
|
||||||
|
2
box.json
2
box.json
@ -31,6 +31,6 @@
|
|||||||
],
|
],
|
||||||
"directories": ["compat", "src/"],
|
"directories": ["compat", "src/"],
|
||||||
"git-version": "git-version",
|
"git-version": "git-version",
|
||||||
"shebang": false,
|
"shebang": "",
|
||||||
"stub": true
|
"stub": true
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
require_once 'geoip2.phar';
|
require_once 'geoip2.phar';
|
||||||
use GeoIp2\Database\Reader;
|
use GeoIp2\Database\Reader;
|
||||||
|
@ -25,17 +25,16 @@ fi
|
|||||||
php composer.phar self-update
|
php composer.phar self-update
|
||||||
php composer.phar update --no-dev
|
php composer.phar update --no-dev
|
||||||
|
|
||||||
if [ ! -f box.phar ]; then
|
# We currently use a custom version of Box due to
|
||||||
wget -O box.phar "https://github.com/box-project/box2/releases/download/2.5.0/box-2.5.0.phar"
|
# https://github.com/box-project/box2/issues/88. There are PRs from Greg with
|
||||||
fi
|
# the fixes.
|
||||||
|
#
|
||||||
|
# if [ ! -f box.phar ]; then
|
||||||
|
# wget -O box.phar "https://github.com/kherge-archive/Box/releases/download/2.4.4/box-2.4.4.phar"
|
||||||
|
# fi
|
||||||
|
|
||||||
php box.phar build
|
../box2/bin/box build
|
||||||
|
./dev-bin/phar-test.php
|
||||||
PHAR_TEST=$(./dev-bin/phar-test.php)
|
|
||||||
if [[ -n $PHAR_TEST ]]; then
|
|
||||||
echo "Phar test outputed non-empty string: $PHAR_TEST"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Download test deps
|
# Download test deps
|
||||||
php composer.phar update
|
php composer.phar update
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace GeoIp2\Model;
|
namespace GeoIp2\Model;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
|
@ -51,8 +51,6 @@ class Client implements ProviderInterface
|
|||||||
private $locales;
|
private $locales;
|
||||||
private $host;
|
private $host;
|
||||||
private $guzzleClient;
|
private $guzzleClient;
|
||||||
private $timeout;
|
|
||||||
private $connectTimeout;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -64,17 +62,13 @@ class Client implements ProviderInterface
|
|||||||
* @param string $host Optional host parameter
|
* @param string $host Optional host parameter
|
||||||
* @param object $guzzleClient Optional Guzzle client to use (to facilitate
|
* @param object $guzzleClient Optional Guzzle client to use (to facilitate
|
||||||
* unit testing).
|
* unit testing).
|
||||||
* @param string $timeout Total transaction timeout in seconds
|
|
||||||
* @param string $connectTimeout Initial connection timeout in seconds
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$userId,
|
$userId,
|
||||||
$licenseKey,
|
$licenseKey,
|
||||||
$locales = array('en'),
|
$locales = array('en'),
|
||||||
$host = 'geoip.maxmind.com',
|
$host = 'geoip.maxmind.com',
|
||||||
$guzzleClient = null,
|
$guzzleClient = null
|
||||||
$timeout = null,
|
|
||||||
$connectTimeout = null
|
|
||||||
) {
|
) {
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->licenseKey = $licenseKey;
|
$this->licenseKey = $licenseKey;
|
||||||
@ -82,8 +76,6 @@ class Client implements ProviderInterface
|
|||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
// To enable unit testing
|
// To enable unit testing
|
||||||
$this->guzzleClient = $guzzleClient;
|
$this->guzzleClient = $guzzleClient;
|
||||||
$this->timeout = $timeout;
|
|
||||||
$this->connectTimeout = $connectTimeout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,14 +180,7 @@ class Client implements ProviderInterface
|
|||||||
|
|
||||||
$client = $this->guzzleClient ?
|
$client = $this->guzzleClient ?
|
||||||
$this->guzzleClient : new GuzzleClient();
|
$this->guzzleClient : new GuzzleClient();
|
||||||
$options = array();
|
$request = $client->get($uri, array('Accept' => 'application/json'));
|
||||||
if ($this->timeout !== null) {
|
|
||||||
$options['timeout'] = $this->timeout;
|
|
||||||
}
|
|
||||||
if ($this->connectTimeout !== null) {
|
|
||||||
$options['connect_timeout'] = $this->connectTimeout;
|
|
||||||
}
|
|
||||||
$request = $client->get($uri, array('Accept' => 'application/json'), $options);
|
|
||||||
$request->setAuth($this->userId, $this->licenseKey);
|
$request->setAuth($this->userId, $this->licenseKey);
|
||||||
$this->setUserAgent($request);
|
$this->setUserAgent($request);
|
||||||
|
|
||||||
|
@ -419,9 +419,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
'abcdef123456',
|
'abcdef123456',
|
||||||
array('en'),
|
array('en'),
|
||||||
'geoip.maxmind.com',
|
'geoip.maxmind.com',
|
||||||
$guzzleClient,
|
$guzzleClient
|
||||||
27,
|
|
||||||
72
|
|
||||||
);
|
);
|
||||||
$client->country('1.2.3.4');
|
$client->country('1.2.3.4');
|
||||||
|
|
||||||
@ -448,21 +446,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertStringMatchesFormat(
|
$this->assertStringMatchesFormat(
|
||||||
'GeoIP2 PHP API (Guzzle%s)',
|
'GeoIP2 PHP API (Guzzle%s)',
|
||||||
$request->getHeader('User-Agent') . '',
|
$request->getHeader('User-Agent') . '',
|
||||||
'request sets Accept header to GeoIP2 PHP API (Guzzle%s)'
|
'request sets Accept header to application/json'
|
||||||
);
|
|
||||||
|
|
||||||
$curlOptions = $request->getCurlOptions();
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
'27000',
|
|
||||||
$curlOptions[CURLOPT_TIMEOUT_MS],
|
|
||||||
'request sets Curl Option Timeout to 27 seconds'
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
'72000',
|
|
||||||
$curlOptions[CURLOPT_CONNECTTIMEOUT_MS],
|
|
||||||
'request sets Curl Option Connect Timeout to 72 seconds'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -480,10 +464,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
$locales,
|
$locales,
|
||||||
'geoip.maxmind.com',
|
'geoip.maxmind.com',
|
||||||
$guzzleClient
|
$guzzleClient
|
||||||
// intentionally not specifying the below, to ensure backwards compatibility
|
|
||||||
//,
|
|
||||||
// 1, // optional timeout
|
|
||||||
// 1 // optional connect timeout
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return $client;
|
return $client;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user