smartdata/smartdata

Data from Open Data providers compiled into easy to use PHP objects

1.0.1 2017-03-06 21:49 UTC

This package is not auto-updated.

Last update: 2024-04-22 23:32:02 UTC


README

68747470733a2f2f63646e2e7261776769742e636f6d2f67656f626173652f636f756e74726965732f6d61737465722f6c6f676f2e706e67

Build Status StyleCI Scrutinizer Code Quality Code Coverage Code Climate Latest Stable Version

Data from Open Data providers compiled into easy to use PHP objects Edit

  1. Features
  2. Sources
  3. Requirements
  4. Installation
  5. Country
  6. Region

Features

  • Multiple languages (Currently only supports English, French and German).
  • Country Database
  • Region Database (Currently only for Canada and the United States).

Sources

Requirements

This library does not require a database, but instead, uses JSON files.

This library uses PHP 5.6+.

Installation

You need to install the library through composer. To do so, use the following command

composer require geobase/countries

Country

Database of all countries in the world.

Properties

  • Names
  • Short Code (Alpha-2 code)
  • Code (Alpha-3 code)
  • Latitude
  • Longitude
  • Bounding Box
  • Currency
  • Continent
  • Population
  • Area
  • Capital
  • Timezone

Examples

Get a list of all countries.

use GeoBase\Country\CountryRepository;
$countryCollection = CountryRepository::findAll();

Get country name in english.

foreach ($countryCollection as $country) {
   echo $country->getNames()->get('en');
}

Order by country name in english.

$countryCollection->orderByName();

Region

Database of all States, Federal Districts and Territories in the United States, Provinces and Territories in Canada.

Properties

  • Name
  • Code (Alpha-2 code)
  • Country
  • Type
  • Latitude
  • Longitude
  • Bounding Box

Examples

Get a list of all regions in the US.

use GeoBase\Country\CountryRepository;
use GeoBase\Regions\RegionRepository;

$country = CountryRepository::findByCode('US');
$regionCollection = RegionRepository::findByCountry($country);

Get region name and type in english.

foreach ($regionCollection as $region) {
   echo $region->getNames()->get('en') . " is a " . 
       $region->getType()::class . " of the " . 
       $country->getNames()->get('en);
}