diff --git a/CHANGELOG.md b/CHANGELOG.md index 20f75ba..1786c5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ 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) ------------------ diff --git a/src/GeoIp2/Database/Reader.php b/src/GeoIp2/Database/Reader.php index 8ba5b61..aff8990 100644 --- a/src/GeoIp2/Database/Reader.php +++ b/src/GeoIp2/Database/Reader.php @@ -38,23 +38,23 @@ use MaxMind\Db\Reader as DbReader; class Reader implements ProviderInterface { private $dbReader; - private $languages; + private $locales; /** * Constructor. * * @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. * @throws \MaxMind\Db\Reader\InvalidDatabaseException if the database * is corrupt or invalid */ public function __construct( $filename, - $languages = array('en') + $locales = array('en') ) { $this->dbReader = new DbReader($filename); - $this->languages = $languages; + $this->locales = $locales; } /** @@ -136,7 +136,7 @@ class Reader implements ProviderInterface $record['traits']['ip_address'] = $ipAddress; $class = "GeoIp2\\Model\\" . $class; - return new $class($record, $this->languages); + return new $class($record, $this->locales); } /** diff --git a/src/GeoIp2/Model/City.php b/src/GeoIp2/Model/City.php index 967bbae..8e88474 100644 --- a/src/GeoIp2/Model/City.php +++ b/src/GeoIp2/Model/City.php @@ -74,18 +74,18 @@ class City extends Country /** * @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->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'])) { return; @@ -94,7 +94,7 @@ class City extends Country foreach ($raw['subdivisions'] as $sub) { array_push( $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() { return empty($this->subdivisions)? - new \GeoIp2\Record\Subdivision(array(), $this->languages): + new \GeoIp2\Record\Subdivision(array(), $this->locales): end($this->subdivisions); } } diff --git a/src/GeoIp2/Model/Country.php b/src/GeoIp2/Model/Country.php index 62ff72f..72c2ead 100644 --- a/src/GeoIp2/Model/Country.php +++ b/src/GeoIp2/Model/Country.php @@ -37,7 +37,7 @@ class Country { private $continent; private $country; - private $languages; + private $locales; private $maxmind; private $registeredCountry; private $representedCountry; @@ -47,30 +47,30 @@ class Country /** * @ignore */ - public function __construct($raw, $languages) + public function __construct($raw, $locales) { $this->raw = $raw; $this->continent = new \GeoIp2\Record\Continent( $this->get('continent'), - $languages + $locales ); $this->country = new \GeoIp2\Record\Country( $this->get('country'), - $languages + $locales ); $this->maxmind = new \GeoIp2\Record\MaxMind($this->get('maxmind')); $this->registeredCountry = new \GeoIp2\Record\Country( $this->get('registered_country'), - $languages + $locales ); $this->representedCountry = new \GeoIp2\Record\RepresentedCountry( $this->get('represented_country'), - $languages + $locales ); $this->traits = new \GeoIp2\Record\Traits($this->get('traits')); - $this->languages = $languages; + $this->locales = $locales; } /** diff --git a/src/GeoIp2/Record/AbstractPlaceRecord.php b/src/GeoIp2/Record/AbstractPlaceRecord.php index 77bde58..638f226 100644 --- a/src/GeoIp2/Record/AbstractPlaceRecord.php +++ b/src/GeoIp2/Record/AbstractPlaceRecord.php @@ -4,14 +4,14 @@ namespace GeoIp2\Record; abstract class AbstractPlaceRecord extends AbstractRecord { - private $languages; + private $locales; /** * @ignore */ - public function __construct($record, $languages) + public function __construct($record, $locales) { - $this->languages = $languages; + $this->locales = $locales; parent::__construct($record); } @@ -29,9 +29,9 @@ abstract class AbstractPlaceRecord extends AbstractRecord private function name() { - foreach ($this->languages as $language) { - if (isset($this->names[$language])) { - return $this->names[$language]; + foreach ($this->locales as $locale) { + if (isset($this->names[$locale])) { + return $this->names[$locale]; } } } diff --git a/src/GeoIp2/Record/City.php b/src/GeoIp2/Record/City.php index 33e7b44..89d9579 100644 --- a/src/GeoIp2/Record/City.php +++ b/src/GeoIp2/Record/City.php @@ -14,7 +14,7 @@ namespace GeoIp2\Record; * @property int $geonameId The GeoName ID for the city. This attribute * 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. * * @property array $names A array map where the keys are locale codes diff --git a/src/GeoIp2/Record/Continent.php b/src/GeoIp2/Record/Continent.php index 3553b4b..50237e8 100644 --- a/src/GeoIp2/Record/Continent.php +++ b/src/GeoIp2/Record/Continent.php @@ -14,7 +14,7 @@ namespace GeoIp2\Record; * is returned by all end points. * * @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. * * @property array $names An array map where the keys are locale codes diff --git a/src/GeoIp2/Record/Country.php b/src/GeoIp2/Record/Country.php index bec2d20..74d1523 100644 --- a/src/GeoIp2/Record/Country.php +++ b/src/GeoIp2/Record/Country.php @@ -18,7 +18,7 @@ namespace GeoIp2\Record; * two-character ISO 3166-1 alpha code} for the country. This attribute is * 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. * * @property array $names An array map where the keys are locale codes and diff --git a/src/GeoIp2/Record/RepresentedCountry.php b/src/GeoIp2/Record/RepresentedCountry.php index 94e78c7..66f6754 100644 --- a/src/GeoIp2/Record/RepresentedCountry.php +++ b/src/GeoIp2/Record/RepresentedCountry.php @@ -22,7 +22,7 @@ namespace GeoIp2\Record; * two-character ISO 3166-1 alpha code} for the country. This attribute is * 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. * * @property array $names An array map where the keys are locale codes and diff --git a/src/GeoIp2/Record/Subdivision.php b/src/GeoIp2/Record/Subdivision.php index 8863dbc..8f97f83 100644 --- a/src/GeoIp2/Record/Subdivision.php +++ b/src/GeoIp2/Record/Subdivision.php @@ -20,7 +20,7 @@ namespace GeoIp2\Record; * http://en.wikipedia.org/wiki/ISO_3166-2 ISO 3166-2 code}. This attribute * 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 * points except Country. * diff --git a/src/GeoIp2/WebService/Client.php b/src/GeoIp2/WebService/Client.php index 651f751..e9e45cb 100644 --- a/src/GeoIp2/WebService/Client.php +++ b/src/GeoIp2/WebService/Client.php @@ -49,7 +49,7 @@ class Client implements ProviderInterface { private $userId; private $licenseKey; - private $languages; + private $locales; private $host; private $guzzleClient; @@ -58,7 +58,7 @@ class Client implements ProviderInterface * * @param int $userId Your MaxMind user ID * @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. * @param string $host Optional host parameter * @param object $guzzleClient Optional Guzzle client to use (to facilitate @@ -67,13 +67,13 @@ class Client implements ProviderInterface public function __construct( $userId, $licenseKey, - $languages = array('en'), + $locales = array('en'), $host = 'geoip.maxmind.com', $guzzleClient = null ) { $this->userId = $userId; $this->licenseKey = $licenseKey; - $this->languages = $languages; + $this->locales = $locales; $this->host = $host; // To enable unit testing $this->guzzleClient = $guzzleClient; @@ -228,7 +228,7 @@ class Client implements ProviderInterface if ($response && $response->isSuccessful()) { $body = $this->handleSuccess($response, $uri); $class = "GeoIp2\\Model\\" . $class; - return new $class($body, $this->languages); + return new $class($body, $this->locales); } else { $this->handleNon200($response, $uri); } diff --git a/tests/GeoIp2/Test/Database/ReaderTest.php b/tests/GeoIp2/Test/Database/ReaderTest.php index c0f0807..890c4c8 100644 --- a/tests/GeoIp2/Test/Database/ReaderTest.php +++ b/tests/GeoIp2/Test/Database/ReaderTest.php @@ -6,7 +6,7 @@ use GeoIp2\Database\Reader; class ReaderTest extends \PHPUnit_Framework_TestCase { - public function testDefaultLanguage() + public function testDefaultLocale() { $reader = new Reader('maxmind-db/test-data/GeoIP2-City-Test.mmdb'); // Needed for PHP 5.3 @@ -20,7 +20,7 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $reader->close(); } - public function testLanguageList() + public function testLocaleList() { $reader = new Reader( 'maxmind-db/test-data/GeoIP2-City-Test.mmdb', diff --git a/tests/GeoIp2/Test/WebService/ClientTest.php b/tests/GeoIp2/Test/WebService/ClientTest.php index 8c4fb38..2c8cdb6 100644 --- a/tests/GeoIp2/Test/WebService/ClientTest.php +++ b/tests/GeoIp2/Test/WebService/ClientTest.php @@ -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->addResponse($response); @@ -460,7 +460,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase $client = new Client( 42, 'abcdef123456', - $languages, + $locales, 'geoip.maxmind.com', $guzzleClient );