2017 © Pedro Peláez
 

library countries

Fast and lightweight utilities for ISO 3166 country data.

image

tjbp/countries

Fast and lightweight utilities for ISO 3166 country data.

  • Sunday, November 8, 2015
  • by tjbp
  • Repository
  • 1 Watchers
  • 1 Stars
  • 153 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

tjbp/countries

A PHP lib providing fast and lightweight utilities for ISO 3166 country data., (*1)

Installation

Run the following within your project directory to install as a dependency:, (*2)

composer require tjbp/countries

Usage

Quick start

use Tjbp\Currencies\Iso3166;

Iso3166::get('GB')->name; // "United Kingdom of Great Britain and Northern Ireland (the)"

More detailed

use Tjbp\Countries\Iso3166;

// Country object is returned with four properties
Iso3166::get('GB')->name; //
Iso3166::get('GB')->alpha2; // GB
Iso3166::get('GB')->alpha3; // GBR
Iso3166::get('GB')->numeric3; // 826

// Alternatively use an object
$countries = new Iso3166;

$countries->get('GB')->alpha2; // GB

// Or get by specific identifiers if you prefer
Iso3166::getByAlpha2('GB')->alpha2; // GB
Iso3166::getByAlpha3('GBR')->alpha2; // GB
Iso3166::getByNumeric3(826)->alpha2; // GB



// Use the Iso3166::get() method to return a Country object
$country = Iso3166::get('GB');

// Country has four properties
$country->name; // "United Kingdom of Great Britain and Northern Ireland (the)"
$country->alpha2; // "GB"
$country->alpha3; // "GBR"
$country->numeric3; // 826

// Alternatively instantiate Iso3166
$iso4217 = new Iso3166;
$country = $iso4217->get('GBP');

// There are also specific identifiers if you prefer
$country = Iso3166::getByAlpha2('GB');
$country = Iso3166::getByAlpha3('GBP');
$country = Iso3166::getByNumeric3(827);

Additionally you can use the HasCountries trait to access the Iso3166::get() method from within an object:, (*3)

use Tjbp\Currencies\HasCountries;

class Example
{
    use HasCountries;

    public method example()
    {
        $this->countries('GB')->name; // "United Kingdom of Great Britain and Northern Ireland (the)"
    }
}

Building

Run bin/build if you wish to regenerate the library using the latest ISO3166 data (though the packaged source should be up-to-date)., (*4)

Contributing

Changes to the Iso3166 class are made to src/templates/Iso3166.php, since src/Iso3166.php will be overwritten when new versions are built., (*5)

Notes

Take a look at https://packagist.org/packages/tjbp/currencies, (*6)

The Versions

08/11 2015

dev-master

9999999-dev

Fast and lightweight utilities for ISO 3166 country data.

  Sources   Download

GPL-3.0

The Development Requires

by Tom Pitcher