bradietilley/country-enums

All (or at least most) countries and their regions formatted as PHP enums

1.5.0 2023-05-16 12:36 UTC

This package is auto-updated.

Last update: 2024-11-16 16:06:31 UTC


README

Static Analysis Tests

All (or at least most) countries and their regions formatted as PHP enums, framework agnostic (of course).

Includes automatic relationships between Countries and Regions, and comes out of the box with svg & png flags. See Authors section for due credit.

Includes a small handful of Laravel helper methods which are made available if this is installed on a Laravel app.

Requirements

PHP 8.1+

Installation

Install it via composer:

composer require bradietilley/country-enums

Usage

Country Enum

All countries are defined by their two-letter codes (ISO 3166-1 alpha-2?).

$country = Country::US;
$country = Country::from('US');

When a country is compiled to array, all of its regions are casted to array as well and are made available in the 'regions' array.

Region Enum

All regions are defined by their country's two-letter code followed by an underscore then a variable length code for the region itself.

$region = Region::US_CA;
$region = Country::from('US_CA');

When a region is compiled to array, its region and country codes are made available as separate key-value pairs alongside the globally-unique "value" (see above).

Author(s)

PHP Enum classes generated by Bradie Tilley.

Specials Thanks

Thanks to all the people who have contributed to the following open source repositories