cromwell/iso3166

There is no license information available for the latest version (1.0) of this package.

A simple package for working with ISO-3166 country codes

1.0 2016-04-30 09:15 UTC

This package is auto-updated.

Last update: 2024-09-10 12:59:30 UTC


README

Scrutinizer Code Quality Build Status Code Climate Test Coverage

Package for interacting with ISO3166 country codes

Example Usage

$iso = new \Cromwell\ISO3166\Countries();

$iso[$iso::UNITED_KINGDOM]->name;

The above isn't hugely useful, it gets more interesting when the code has been stored and retrieved from persistence:

$iso = new \Cromwell\ISO3166\Countries();

$iso[$customer->country]->name;

You can also use jsonSerialize() either for JSON encoding or as a convenient way to get a multidimensional array for use to construct a <select> box of code => name.

Subsets

You can construct any subset of countries by passing an array of codes. The package contains an EU subset at the moment, you can use the EU class as an example of how to do it or if you just wanted EU countries, there you go.

Passing an array of codes is useful if they've been selected on the fly by an end user. It could be a list of countries that they ship to, for example. In this instance it's likely to change between customers or be initialised from the database. If it's a static list, such as a continent or EU membership, use the EU example and extend the base Countries class to implement your subset.