d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

A Collection of ISO standards as PHP Enums

The PrinsFrank/standards package is a collection of standards as PHP Enums, such as ISO3166, ISO4217, ISO639, and more. Specifically, this package includes support for common language ISO codes, country codes, and currencies.

For example, ISO 3166 deals with country code standards, such as two-letter country codes, three letter cords, and alpha-numeric codes:

1// ISO3166_1_Alpha_2::Netherlands

2$valueAlpha2 = ISO3166_1_Alpha_2::from('NL');

3$valueAlpha2->value; // 'NL'

4$valueAlpha2->name; // 'Netherlands'

5 

6// ISO3166_1_Alpha_3::Netherlands

7$valueAlpha2->toISO3166_1_Alpha_3();

8// ISO3166_1_Numeric::Netherlands

9$valueAlpha2->toISO3166_1_Numeric();

10 

11// Alpha-3

12// ISO3166_1_Alpha_3::Netherlands

13$valueAlpha3 = ISO3166_1_Alpha_3::from('NLD');

14$valueAlpha3->value; // 'NLD'

15$valueAlpha3->name; // 'Netherlands'

16 

17// Numeric

18// ISO3166_1_Numeric::Netherlands

19ISO3166_1_Numeric::from('528');

20ISO3166_1_Numeric::fromInt(528);

21 

22$valueNumeric->value; // '528'

23$valueNumeric->name; // 'Netherlands'

This package also includes support for ISO 4217 currency codes:

1// Alpha-3

2// ISO4217_Alpha3::Euro

3$valueAlpha3 = ISO4217_Alpha3::from('EUR');

4$valueAlpha3->value; // 'EUR'

5$valueAlpha3->name; // 'Euro'

6 

7// Numeric

8// ISO4217_Numeric::Euro

9$valueNumeric = ISO4217_Numeric::from('978');

10$valueNumeric = ISO4217_Numeric::fromInt(978);

11$valueNumeric->value; // '978'

12$valueNumeric->name; // 'Euro'

Language support (ISO 639) is another helpful standard enum this package provides:

1// ISO639_1_Alpha_2::Dutch_Flemish

2$valueAlpha2 = ISO639_1_Alpha_2::from('nl');

3$valueAlpha2->value; // 'nl'

4$valueAlpha2->name; // 'Dutch_Flemish'

Enums are supported in PHP as of PHP 8.1. Laravel also includes Enum features such as casting Eloquent attributes to PHP “backed” enums and implicit enum route binding that you might want to check out if you’re new to Enums.

You can learn about this package, get full installation instructions, and view the source code on GitHub.

Credit: Source link

Previous Next
Close
Test Caption
Test Description goes like this