Download the PHP package tiny-blocks/country without Composer
On this page you can find all versions of the php package tiny-blocks/country. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tiny-blocks/country
More information about tiny-blocks/country
Files in tiny-blocks/country
Package country
Short Description Provides ISO 3166-1 country and ISO 3166-2 subdivision value objects for PHP, with Alpha-2, Alpha-3, numeric, and IANA timezone resolution.
License MIT
Homepage https://github.com/tiny-blocks/country
Informations about the package country
Country
- Overview
- Installation
- How to use
- Country codes
- Country
- Creating from objects
- Creating from string
- Safe creation
- Subdivisions
- All countries
- Timezones
- License
- Contributing
Overview
Provides ISO 3166-1 country and
ISO 3166-2 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, 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
How to use
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.
The numeric code keeps the ISO leading zeros as a string and exposes them as an integer through toInteger.
Country
A Country can be created from any code object with from, or from a string with fromString. The name, both alpha
codes, the numeric code, the timezones, and the subdivisions are read through methods.
Creating from objects
The same country is produced from its Alpha-3 or numeric code, since from canonicalizes to the Alpha-2 code.
Creating from string
fromString accepts an Alpha-2, Alpha-3, or numeric code as a string. It throws InvalidCountryCode when the string
matches no known code.
Safe creation
Use tryFromString to validate external input without handling exceptions. It returns null when the code matches no
known Alpha-2, Alpha-3, or numeric code.
Subdivisions
Each Country exposes its ISO 3166-2 subdivisions as a Subdivisions collection, which may be empty for territories
that have none. A Subdivision can also be created directly from its code with fromString or tryFromString.
All countries
Countries::all returns every ISO 3166-1 country as a collection of Country handles.
Timezones
Every Country exposes a CountryTimezones collection, built from the IANA timezone database through PHP. The first
identifier is the default, and it falls back to UTC for territories without an assigned timezone.
License
Country is licensed under MIT.
Contributing
Please follow the contributing guidelines to contribute to the project.
All versions of country with dependencies
tiny-blocks/collection Version ^2.5
tiny-blocks/time Version ^2.3
tiny-blocks/value-object Version ^5.0