PHPackages                             tiny-blocks/country - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. tiny-blocks/country

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

tiny-blocks/country
===================

Provides ISO 3166-1 country and ISO 3166-2 subdivision value objects for PHP, with Alpha-2, Alpha-3, numeric, and IANA timezone resolution.

5.0.0(1mo ago)322.4k↓93%MITPHPPHP ^8.5CI passing

Since Jul 26Pushed 1mo agoCompare

[ Source](https://github.com/tiny-blocks/country)[ Packagist](https://packagist.org/packages/tiny-blocks/country)[ Docs](https://github.com/tiny-blocks/country)[ RSS](/packages/tiny-blocks-country/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (10)Dependencies (21)Versions (18)Used By (0)

Country
=======

[](#country)

[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://github.com/tiny-blocks/country/blob/main/LICENSE)

- [Overview](#overview)
- [Installation](#installation)
- [How to use](#how-to-use)
    - [Country codes](#country-codes)
    - [Country](#country)
        - [Creating from objects](#creating-from-objects)
        - [Creating from string](#creating-from-string)
        - [Safe creation](#safe-creation)
    - [Subdivisions](#subdivisions)
    - [All countries](#all-countries)
    - [Timezones](#timezones)
- [License](#license)
- [Contributing](#contributing)

Overview
--------

[](#overview)

Provides [ISO 3166-1](https://www.iso.org/iso-3166-country-codes.html) country and [ISO 3166-2](https://www.iso.org/glossary-for-iso-3166.html) subdivision value objects for PHP. A `Country` is a lazy handle over an Alpha-2 code that resolves its name, its Alpha-3 and numeric codes, its [IANA timezones](https://www.iana.org), and its subdivisions on demand. A `Subdivision` is the same kind of handle one level down, resolving its name, its category, and its owning country from the ISO 3166-2 code.

Construction works from any of the three code variants (Alpha-2, Alpha-3, or numeric), with automatic conversion between them. The data is generated from the ISO 3166 standard. Names are the official ISO English short names, so the values are stable and citable rather than derived. The library builds on the tiny-blocks value-object contract for immutability and structural equality, on tiny-blocks/time for timezones, and on tiny-blocks/collection for the country and subdivision collections.

Installation
------------

[](#installation)

```
composer require tiny-blocks/country
```

How to use
----------

[](#how-to-use)

### Country codes

[](#country-codes)

Each country has three ISO 3166-1 representations: a two-letter `Alpha2Code`, a three-letter `Alpha3Code`, and a three-digit `NumericCode`. Every code converts to the other two and to its string value.

```
