Home >PHP Framework >Laravel >Laravel extension recommendation: enumeration package 'standards' (ISO standards collection)

Laravel extension recommendation: enumeration package 'standards' (ISO standards collection)

青灯夜游
青灯夜游forward
2022-10-18 21:00:051574browse

Laravel extension recommendation: enumeration package 'standards' (ISO standards collection)

PrinsFrank/standards package is a collection of standards such as PHP enumerations, such as ISO3166, ISO4217, ISO639, etc. Specifically, this package includes support for universal language ISO codes, country codes, and currencies.

For example, ISO 3166 handles country code standards such as two-letter country codes, three-letter lines, and alphanumeric codes:

// ISO3166_1_Alpha_2::Netherlands
$valueAlpha2 = ISO3166_1_Alpha_2::from('NL');
$valueAlpha2->value; // 'NL'
$valueAlpha2->name; // 'Netherlands'

// ISO3166_1_Alpha_3::Netherlands
$valueAlpha2->toISO3166_1_Alpha_3();
// ISO3166_1_Numeric::Netherlands
$valueAlpha2->toISO3166_1_Numeric();

// Alpha-3
// ISO3166_1_Alpha_3::Netherlands
$valueAlpha3 = ISO3166_1_Alpha_3::from('NLD');
$valueAlpha3->value; // 'NLD'
$valueAlpha3->name; // 'Netherlands'

// Numeric
// ISO3166_1_Numeric::Netherlands
ISO3166_1_Numeric::from('528');
ISO3166_1_Numeric::fromInt(528);

$valueNumeric->value; // '528'
$valueNumeric->name; // 'Netherlands'

This package also includes support for ISO 4217 currency codes:

// Alpha-3
// ISO4217_Alpha3::Euro
$valueAlpha3 = ISO4217_Alpha3::from('EUR');
$valueAlpha3->value; // 'EUR'
$valueAlpha3->name; // 'Euro'

// Numeric
// ISO4217_Numeric::Euro
$valueNumeric = ISO4217_Numeric::from('978');
$valueNumeric = ISO4217_Numeric::fromInt(978);
$valueNumeric->value; // '978'
$valueNumeric->name; // 'Euro'

Language support (ISO 639) is Another useful standard enumeration provided by this package:

// ISO639_1_Alpha_2::Dutch_Flemish
$valueAlpha2 = ISO639_1_Alpha_2::from('nl');
$valueAlpha2->value; // 'nl'
$valueAlpha2->name; // 'Dutch_Flemish'

Since PHP 8.1, PHP supports enumerations. Laravel also includes enumeration capabilities, such as Converting Eloquent properties to PHP "supported" enumerations and Implicit enum routing bindings, which you may want to check out if you are new to Enums.

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

Original address: https://laravel-news.com/iso-standards-as-php-enums

Translation address: https://learnku.com/laravel/ t/68870

[Related recommendations: laravel video tutorial]

The above is the detailed content of Laravel extension recommendation: enumeration package 'standards' (ISO standards collection). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete