承接 steefdw/standards-enums 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

steefdw/standards-enums

最新稳定版本:v0.1.8

Composer 安装命令:

composer require steefdw/standards-enums

包简介

The Standards Enums package provides a simple and consistent way to work with countries, languages, currencies, and locales using enums.Each Enum comes with methods for accessing related information, like the name, flag, description, and more.Additionally, helper methods are provided to easily get a

README 文档

README

The Standards Enums package provides a simple and consistent way to work with countries, languages, currencies, and locales using enums.

Each Enum comes with methods for accessing related information, like the name, flag, description, and more. Additionally, helper methods are provided to easily get all possible values or sort them by their name in a given language. These methods can be used with all Enum classes, regardless of whether they represent languages, countries, currencies, or locales.

Standards Enums provides you access to lists of various ISO standards:

Enum in this packageISO standard
CountriesISO 3166-1
CurrenciesISO 4217
LanguagesISO 639
Locales(not ISO)

Much of the code in this package is automatically generated with the data from https://salsa.debian.org/iso-codes-team/iso-codes.

Documentation

Installation

composer require steefdw/standards-enums

Usage

Countries example:

$country = CountryAlpha2::tryFrom('nl'); // CountryAlpha2::NL

$countryName = $country->getName()->value;           // 'Netherlands'
$countryAlpha2 = $countryName->getAlpha2()->value;   // 'nl'
$countryAlpha3 = $countryAlpha2->getAlpha3()->value; // 'NLD'
$countryFlag = $countryAlpha3->getFlag()->value;     // '🇳🇱'
$countryNumber = $countryFlag->getNumeric()->value;  // '528'
$countryContinent = $country->getContinent()->value; // 'Europe'
$countryCurrencies = $country->getCurrencies();      // ['EUR' => CurrencyName::EUR]

// these methods work for all country Enums

Currencies example:

$currency = CurrencyName::tryFrom('Euro'); // CurrencyName::EUR

$currencyName = $currency->getName()->value;      // 'Euro'
$currencyAlpha3 = $currency->getAlpha3()->value;  // 'EUR'
$currencyNumber = $currency->getNumeric()->value; // '978'
$currencyCountries = $currency->getCountries();   // [
//    'AD' => CountryName::AD, // Andorra
//    'AT' => CountryName::AT, // Austria
//    'BE' => CountryName::BE, // Belgium
//    ...]

// these methods work for all currency Enums

Languages example:

$language = LanguageAlpha2::tryFrom('nl'); // LanguageAlpha2::NLD

$languageName = $language->getName()->value;           // 'Dutch; Flemish'
$languageAlpha2 = $languageName->getAlpha2()->value;   // 'nl'
$languageAlpha3 = $languageAlpha2->getAlpha3()->value; // 'nld'
// these methods work for all language Enums

Locales example:

$locale = LocaleCode::tryFromName('nl_BE'); // LocaleCode::NL_BE

$description = $locale->getDescription(); // LocaleDescription::NL_BE
$description->value;                 // 'Dutch (Belgium)'
$locale->getLanguage()->value;       // 'Dutch; Flemish'
$locale->getCountry()->value;        // 'Belgium'
// these methods work for all locale Enums

See the usage pages for more information:

Please refer to these sections of the documentation for more detailed information on how to use each enum type.

Testing

composer test

Or:

make test

Contributing

  • make sure the code validation succeeds. You can run it with make validate.
  • make sure all tests succeed. You can run them with make test.
  • make sure all code is tested.

License

The MIT License. Please see Licence File for more information.

统计信息

  • 总下载量: 63.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-08