Renamed languages to locales in the code
This commit is contained in:
parent
b8188bc558
commit
234dcaff7c
|
@ -1,6 +1,13 @@
|
||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.5.0 (2013-10-XX)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
* Renamed $languages constructor parameters to $locales for both the Client
|
||||||
|
and Reader classes.
|
||||||
|
* Documentation and code clean-up (Ben Morel).
|
||||||
|
|
||||||
0.4.0 (2013-07-16)
|
0.4.0 (2013-07-16)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|
|
@ -38,23 +38,23 @@ use MaxMind\Db\Reader as DbReader;
|
||||||
class Reader implements ProviderInterface
|
class Reader implements ProviderInterface
|
||||||
{
|
{
|
||||||
private $dbReader;
|
private $dbReader;
|
||||||
private $languages;
|
private $locales;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param string $filename The path to the GeoIP2 database file.
|
* @param string $filename The path to the GeoIP2 database file.
|
||||||
* @param array $languages List of locale codes to use in name property
|
* @param array $locales List of locale codes to use in name property
|
||||||
* from most preferred to least preferred.
|
* from most preferred to least preferred.
|
||||||
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
|
* @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database
|
||||||
* is corrupt or invalid
|
* is corrupt or invalid
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$filename,
|
$filename,
|
||||||
$languages = array('en')
|
$locales = array('en')
|
||||||
) {
|
) {
|
||||||
$this->dbReader = new DbReader($filename);
|
$this->dbReader = new DbReader($filename);
|
||||||
$this->languages = $languages;
|
$this->locales = $locales;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,7 +136,7 @@ class Reader implements ProviderInterface
|
||||||
$record['traits']['ip_address'] = $ipAddress;
|
$record['traits']['ip_address'] = $ipAddress;
|
||||||
$class = "GeoIp2\\Model\\" . $class;
|
$class = "GeoIp2\\Model\\" . $class;
|
||||||
|
|
||||||
return new $class($record, $this->languages);
|
return new $class($record, $this->locales);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -74,18 +74,18 @@ class City extends Country
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
public function __construct($raw, $languages)
|
public function __construct($raw, $locales)
|
||||||
{
|
{
|
||||||
parent::__construct($raw, $languages);
|
parent::__construct($raw, $locales);
|
||||||
|
|
||||||
$this->city = new \GeoIp2\Record\City($this->get('city'), $languages);
|
$this->city = new \GeoIp2\Record\City($this->get('city'), $locales);
|
||||||
$this->location = new \GeoIp2\Record\Location($this->get('location'));
|
$this->location = new \GeoIp2\Record\Location($this->get('location'));
|
||||||
$this->postal = new \GeoIp2\Record\Postal($this->get('postal'));
|
$this->postal = new \GeoIp2\Record\Postal($this->get('postal'));
|
||||||
|
|
||||||
$this->createSubdivisions($raw, $languages);
|
$this->createSubdivisions($raw, $locales);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createSubdivisions($raw, $languages)
|
private function createSubdivisions($raw, $locales)
|
||||||
{
|
{
|
||||||
if (!isset($raw['subdivisions'])) {
|
if (!isset($raw['subdivisions'])) {
|
||||||
return;
|
return;
|
||||||
|
@ -94,7 +94,7 @@ class City extends Country
|
||||||
foreach ($raw['subdivisions'] as $sub) {
|
foreach ($raw['subdivisions'] as $sub) {
|
||||||
array_push(
|
array_push(
|
||||||
$this->subdivisions,
|
$this->subdivisions,
|
||||||
new \GeoIp2\Record\Subdivision($sub, $languages)
|
new \GeoIp2\Record\Subdivision($sub, $locales)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ class City extends Country
|
||||||
private function mostSpecificSubdivision()
|
private function mostSpecificSubdivision()
|
||||||
{
|
{
|
||||||
return empty($this->subdivisions)?
|
return empty($this->subdivisions)?
|
||||||
new \GeoIp2\Record\Subdivision(array(), $this->languages):
|
new \GeoIp2\Record\Subdivision(array(), $this->locales):
|
||||||
end($this->subdivisions);
|
end($this->subdivisions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class Country
|
||||||
{
|
{
|
||||||
private $continent;
|
private $continent;
|
||||||
private $country;
|
private $country;
|
||||||
private $languages;
|
private $locales;
|
||||||
private $maxmind;
|
private $maxmind;
|
||||||
private $registeredCountry;
|
private $registeredCountry;
|
||||||
private $representedCountry;
|
private $representedCountry;
|
||||||
|
@ -47,30 +47,30 @@ class Country
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
public function __construct($raw, $languages)
|
public function __construct($raw, $locales)
|
||||||
{
|
{
|
||||||
$this->raw = $raw;
|
$this->raw = $raw;
|
||||||
|
|
||||||
$this->continent = new \GeoIp2\Record\Continent(
|
$this->continent = new \GeoIp2\Record\Continent(
|
||||||
$this->get('continent'),
|
$this->get('continent'),
|
||||||
$languages
|
$locales
|
||||||
);
|
);
|
||||||
$this->country = new \GeoIp2\Record\Country(
|
$this->country = new \GeoIp2\Record\Country(
|
||||||
$this->get('country'),
|
$this->get('country'),
|
||||||
$languages
|
$locales
|
||||||
);
|
);
|
||||||
$this->maxmind = new \GeoIp2\Record\MaxMind($this->get('maxmind'));
|
$this->maxmind = new \GeoIp2\Record\MaxMind($this->get('maxmind'));
|
||||||
$this->registeredCountry = new \GeoIp2\Record\Country(
|
$this->registeredCountry = new \GeoIp2\Record\Country(
|
||||||
$this->get('registered_country'),
|
$this->get('registered_country'),
|
||||||
$languages
|
$locales
|
||||||
);
|
);
|
||||||
$this->representedCountry = new \GeoIp2\Record\RepresentedCountry(
|
$this->representedCountry = new \GeoIp2\Record\RepresentedCountry(
|
||||||
$this->get('represented_country'),
|
$this->get('represented_country'),
|
||||||
$languages
|
$locales
|
||||||
);
|
);
|
||||||
$this->traits = new \GeoIp2\Record\Traits($this->get('traits'));
|
$this->traits = new \GeoIp2\Record\Traits($this->get('traits'));
|
||||||
|
|
||||||
$this->languages = $languages;
|
$this->locales = $locales;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,14 +4,14 @@ namespace GeoIp2\Record;
|
||||||
|
|
||||||
abstract class AbstractPlaceRecord extends AbstractRecord
|
abstract class AbstractPlaceRecord extends AbstractRecord
|
||||||
{
|
{
|
||||||
private $languages;
|
private $locales;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
public function __construct($record, $languages)
|
public function __construct($record, $locales)
|
||||||
{
|
{
|
||||||
$this->languages = $languages;
|
$this->locales = $locales;
|
||||||
parent::__construct($record);
|
parent::__construct($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@ abstract class AbstractPlaceRecord extends AbstractRecord
|
||||||
|
|
||||||
private function name()
|
private function name()
|
||||||
{
|
{
|
||||||
foreach ($this->languages as $language) {
|
foreach ($this->locales as $locale) {
|
||||||
if (isset($this->names[$language])) {
|
if (isset($this->names[$locale])) {
|
||||||
return $this->names[$language];
|
return $this->names[$locale];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace GeoIp2\Record;
|
||||||
* @property int $geonameId The GeoName ID for the city. This attribute
|
* @property int $geonameId The GeoName ID for the city. This attribute
|
||||||
* is returned by all end points.
|
* is returned by all end points.
|
||||||
*
|
*
|
||||||
* @property string $name The name of the city based on the languages list
|
* @property string $name The name of the city based on the locales list
|
||||||
* passed to the constructor. This attribute is returned by all end points.
|
* passed to the constructor. This attribute is returned by all end points.
|
||||||
*
|
*
|
||||||
* @property array $names A array map where the keys are locale codes
|
* @property array $names A array map where the keys are locale codes
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace GeoIp2\Record;
|
||||||
* is returned by all end points.
|
* is returned by all end points.
|
||||||
*
|
*
|
||||||
* @property string $name Returns the name of the continent based on the
|
* @property string $name Returns the name of the continent based on the
|
||||||
* languages list passed to the constructor. This attribute is returned by
|
* locales list passed to the constructor. This attribute is returned by
|
||||||
* all end points.
|
* all end points.
|
||||||
*
|
*
|
||||||
* @property array $names An array map where the keys are locale codes
|
* @property array $names An array map where the keys are locale codes
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace GeoIp2\Record;
|
||||||
* two-character ISO 3166-1 alpha code} for the country. This attribute is
|
* two-character ISO 3166-1 alpha code} for the country. This attribute is
|
||||||
* returned by all end points.
|
* returned by all end points.
|
||||||
*
|
*
|
||||||
* @property string $name The name of the country based on the languages list
|
* @property string $name The name of the country based on the locales list
|
||||||
* passed to the constructor. This attribute is returned by all end points.
|
* passed to the constructor. This attribute is returned by all end points.
|
||||||
*
|
*
|
||||||
* @property array $names An array map where the keys are locale codes and
|
* @property array $names An array map where the keys are locale codes and
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace GeoIp2\Record;
|
||||||
* two-character ISO 3166-1 alpha code} for the country. This attribute is
|
* two-character ISO 3166-1 alpha code} for the country. This attribute is
|
||||||
* returned by all end points.
|
* returned by all end points.
|
||||||
*
|
*
|
||||||
* @property string $name The name of the country based on the languages list
|
* @property string $name The name of the country based on the locales list
|
||||||
* passed to the constructor. This attribute is returned by all end points.
|
* passed to the constructor. This attribute is returned by all end points.
|
||||||
*
|
*
|
||||||
* @property array $names An array map where the keys are locale codes and
|
* @property array $names An array map where the keys are locale codes and
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace GeoIp2\Record;
|
||||||
* http://en.wikipedia.org/wiki/ISO_3166-2 ISO 3166-2 code}. This attribute
|
* http://en.wikipedia.org/wiki/ISO_3166-2 ISO 3166-2 code}. This attribute
|
||||||
* is returned by all end points except Country.
|
* is returned by all end points except Country.
|
||||||
*
|
*
|
||||||
* @property string $name The name of the subdivision based on the languages
|
* @property string $name The name of the subdivision based on the locales
|
||||||
* list passed to the constructor. This attribute is returned by all end
|
* list passed to the constructor. This attribute is returned by all end
|
||||||
* points except Country.
|
* points except Country.
|
||||||
*
|
*
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Client implements ProviderInterface
|
||||||
{
|
{
|
||||||
private $userId;
|
private $userId;
|
||||||
private $licenseKey;
|
private $licenseKey;
|
||||||
private $languages;
|
private $locales;
|
||||||
private $host;
|
private $host;
|
||||||
private $guzzleClient;
|
private $guzzleClient;
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class Client implements ProviderInterface
|
||||||
*
|
*
|
||||||
* @param int $userId Your MaxMind user ID
|
* @param int $userId Your MaxMind user ID
|
||||||
* @param string $licenseKey Your MaxMind license key
|
* @param string $licenseKey Your MaxMind license key
|
||||||
* @param array $languages List of locale codes to use in name property
|
* @param array $locales List of locale codes to use in name property
|
||||||
* from most preferred to least preferred.
|
* from most preferred to least preferred.
|
||||||
* @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
|
||||||
|
@ -67,13 +67,13 @@ class Client implements ProviderInterface
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$userId,
|
$userId,
|
||||||
$licenseKey,
|
$licenseKey,
|
||||||
$languages = array('en'),
|
$locales = array('en'),
|
||||||
$host = 'geoip.maxmind.com',
|
$host = 'geoip.maxmind.com',
|
||||||
$guzzleClient = null
|
$guzzleClient = null
|
||||||
) {
|
) {
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->licenseKey = $licenseKey;
|
$this->licenseKey = $licenseKey;
|
||||||
$this->languages = $languages;
|
$this->locales = $locales;
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
// To enable unit testing
|
// To enable unit testing
|
||||||
$this->guzzleClient = $guzzleClient;
|
$this->guzzleClient = $guzzleClient;
|
||||||
|
@ -228,7 +228,7 @@ class Client implements ProviderInterface
|
||||||
if ($response && $response->isSuccessful()) {
|
if ($response && $response->isSuccessful()) {
|
||||||
$body = $this->handleSuccess($response, $uri);
|
$body = $this->handleSuccess($response, $uri);
|
||||||
$class = "GeoIp2\\Model\\" . $class;
|
$class = "GeoIp2\\Model\\" . $class;
|
||||||
return new $class($body, $this->languages);
|
return new $class($body, $this->locales);
|
||||||
} else {
|
} else {
|
||||||
$this->handleNon200($response, $uri);
|
$this->handleNon200($response, $uri);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use GeoIp2\Database\Reader;
|
||||||
|
|
||||||
class ReaderTest extends \PHPUnit_Framework_TestCase
|
class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function testDefaultLanguage()
|
public function testDefaultLocale()
|
||||||
{
|
{
|
||||||
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
$reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb');
|
||||||
// Needed for PHP 5.3
|
// Needed for PHP 5.3
|
||||||
|
@ -20,7 +20,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||||
$reader->close();
|
$reader->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLanguageList()
|
public function testLocaleList()
|
||||||
{
|
{
|
||||||
$reader = new Reader(
|
$reader = new Reader(
|
||||||
'maxmind-db/test-data/GeoIP2-City-Test.mmdb',
|
'maxmind-db/test-data/GeoIP2-City-Test.mmdb',
|
||||||
|
|
|
@ -450,7 +450,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function client($response, $languages = array('en'))
|
private function client($response, $locales = array('en'))
|
||||||
{
|
{
|
||||||
$plugin = new MockPlugin();
|
$plugin = new MockPlugin();
|
||||||
$plugin->addResponse($response);
|
$plugin->addResponse($response);
|
||||||
|
@ -460,7 +460,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||||
$client = new Client(
|
$client = new Client(
|
||||||
42,
|
42,
|
||||||
'abcdef123456',
|
'abcdef123456',
|
||||||
$languages,
|
$locales,
|
||||||
'geoip.maxmind.com',
|
'geoip.maxmind.com',
|
||||||
$guzzleClient
|
$guzzleClient
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user