farzai / geonames
This package provides a simple way to download Geonames data and format it for friendly use.
Fund package maintenance!
parsilver
Requires
- php: >=7.4
- ext-json: *
- ext-zip: *
- psr/http-message: ^1.0
- squizlabs/php_codesniffer: ^3.7
Requires (Dev)
- guzzlehttp/guzzle: ^7.5
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.5
README
This package provides a simple way to download Geonames data and format it for friendly use. (https://www.geonames.org/)
Requirements
PHP ^8.1
ext-curl
ext-json
ext-zip
Setup
You can install the package via Composer:
composer require farzai/geonames
Example
use Farzai\Geonames\Client; // Create a new client $client = new Client(); // Get all countries and return $resource $resource = $client->getCountryInfo(); // \Farzai\Geonames\Resource\CollectionResource // Now, you can access the data using the following methods: $countries = $resource->asArray(); // Array $json = $resource->asJson(); // String // Or acccess data as entity foreach ($resource->all() as $country) { /** @var \Farzai\Geonames\Entities\CountryEntity $country */ echo $country->name; }
Available methods
Get all countries
// GET: https://download.geonames.org/export/dump/countryInfo.txt $resource = $client->getCountryInfo(); // $entity instanceof \Farzai\Geonames\Entities\CountryEntity foreach ($resource->all() as $entity) { echo $entity->iso; // ... }
Get languages
// GET: https://download.geonames.org/export/dump/iso-languagecodes.txt $resource = $client->getLanguages(); // $entity instanceof \Farzai\Geonames\Entities\LanguageEntity foreach ($resource->all() as $entity) { // ... }
Geonames available resources
// GET: https://download.geonames.org/export/dump $resource = $client->getGeonamesAvailable(); /** @var string[] $countryCodes */ $countryCodes = $resource->all();
Geonames by country code
// GET: https://download.geonames.org/export/dump/{countryCode}.zip $resource = $client->getGeonamesByCountryCode('TH'); // $entity instanceof \Farzai\Geonames\Entities\GeonameEntity foreach ($resource->all() as $entity) { // ... }
Alternate names available resources
// GET: https://download.geonames.org/export/dump/alternatenames $resource = $client->getAlternateNamesAvailable(); /** @var string[] $countryCodes */ $countryCodes = $resource->all();
Alternate names by country code
// GET: https://download.geonames.org/export/dump/alternatenames/{countryCode}.zip $resource = $client->getAlternateNamesByCountryCode('TH'); // $entity instanceof \Farzai\Geonames\Entities\AlternateNameEntity foreach ($resource->all() as $entity) { // }
License
The MIT License (MIT). Please see License File for more information.