bradietilley / country-enums
All (or at least most) countries and their regions formatted as PHP enums
Installs: 7 171
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
Requires (Dev)
- laravel/pint: ^1.10
- pestphp/pest: ^2.6
- pestphp/pest-plugin-laravel: ^2.0
- rector/rector: ^0.16.0
README
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
- Country/Region Data: https://github.com/country-regions/country-region-data
- SVG/PNG Flags: https://github.com/hampusborgos/country-flags