steefdw/standards-enums
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 package | ISO standard |
|---|---|
| Countries | ISO 3166-1 |
| Currencies | ISO 4217 |
| Languages | ISO 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
- Full documentation: https://steefdw.gitlab.io/standards-enums
- Short documentation: this readme.
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.
- Using the countries enums
- Using the currencies enums
- Using the languages enums
- Using the locales enums
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.
steefdw/standards-enums 适用场景与选型建议
steefdw/standards-enums 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 83.59k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 10 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「locale」 「enumeration」 「countries」 「standards」 「ISO 3166」 「languages」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 steefdw/standards-enums 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 steefdw/standards-enums 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 steefdw/standards-enums 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Package for convenient work with Laravel's localization features
List of all countries with names and ISO 3166-1 codes in all languages and data formats for Laravel
Laravel 5.2 package that provides basic geographical data like Countries, Regions and Cities.
Compatibility layer for emulating enumerations in PHP < 8.1 and native enumerations in PHP >= 8.1
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
A Lithium plugin with additional g11n resources constituting the Lithium Locale Data Repository.
统计信息
- 总下载量: 83.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 32
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-08