Blog Detail

18

Oct
Standards - An Awesome Collection of Standards as PHP Enums cover image

arrow_back Standards - An Awesome Collection of Standards as PHP Enums

This package includes a collection of standards as PHP Enums like ISO3166, ISO4217, ISO639…

Daily updates from their sources, whether it is ISO or IANA directly, or a maintaining party like the six groups or the US library of congress.

Installation & Setup

Note: Make sure you are running PHP 8.1 or higher to use this package

To start right away, run the following command in your composer project;

composer require prinsfrank/standards

Or for development only;

composer require prinsfrank/standards --dev

How this package works

This package implements a bunch of specs as PHP Enums, so you can typehint them in methods. Currently, all specs are implemented as backed enums. That means that besides a name, they have also an internal ‘value’, either as an integer or a string.

In the Country, Currency, and language specifications, there is also a relation between different enums. For example, the Alpha2 country code ‘NL’ is related to the Alpha3 ‘NLD’, the numeric value ‘528’, and the name ‘Netherlands (the)’. Internally, these specs rely on the fact that the keys for these values are identical, so it is possible to convert between these.

Country

All the Alpha2, Alpha3, Numeric, and Name values have a corresponding enum in the other country enums. These can be converted using their corresponding methods.

Key ISO3166_1_Alpha_2 ISO3166_1_Alpha_3 ISO3166_1_Numeric ISO3166_1_Name
Netherlands NL NLD 528 Netherlands (the)
Turkey TR TUR 792 Türkiye

Currency

All the Alpha3, Numeric, and Name values have a corresponding enum in the other currency enums. These can be converted using their corresponding methods.

Key ISO4217_Alpha_3 ISO4217_Numeric ISO4217_Name
Euro EUR 978 Euro
Turkish_Lira TRY 949 Turkish Lira

Language

The language specification is a bit more complex, as there are 20 alpha3 codes that have both a Bibliographic and a Terminology code. All the other ones have a common one. So if you decide you want the alpha3 representation of an alpha2 code, you can convert it to either Terminology or Bibliographic, where if it is not available you will get an instance of the common enum.

Country Calling Codes

Country calling codes are quite straightforward. One Exception is that the +1 prefix is used across a lot of countries, and there is no standard for sub-numbering plans.

Key ITU_T_E_164
Netherlands_Kingdom_of_the 31
Turkey 90

HTTP Status Codes

HTTP Status codes are quite straightforward. For some code examples, you can look in the documentation.

Key HttpStatusCode
Moved_Permanently 301
Not_Found 401

For more details & source code, Please visit Github

Published at : 18-10-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project