承接 alexconrad/enum-countries 相关项目开发

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

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

alexconrad/enum-countries

最新稳定版本:v1.1.2-stable

Composer 安装命令:

composer require alexconrad/enum-countries

包简介

关键字:

README 文档

README

Test Coverage Badge Latest Stable Version Total Downloads License PHP Version Require

enum-countries

Provides ENUM classes for ISO-3166-1 alpha2 and alpha3 country codes.

Installation

composer require alexconrad/enum-countries

Usage

use EnumCountriesIso3166\Country;
use EnumCountriesIso3166\CountryAlpha3;
use EnumCountriesIso3166\CountryService;

class MyClass
{
    public function __construct(
        private readonly CountryService $countryService
    ) {
    }

    public function save(Country $alpha2, CountryAlpha3 $alpha3, int $numericCode)
    {

        echo "ISO-3166-1 alpha2 Country Code:" . $alpha2->name . "\n";
        echo "ISO-3166-1 alpha3 Country Code:" . $alpha3->name . "\n";
        echo "ISO-3166-1 numeric Country Code:" . $numericCode . "\n";

        echo "Get country name from alpha2:" . $this->countryService->getName($alpha2) . "\n";
        echo "Get country name from alpha3:" . $this->countryService->getName($alpha3) . "\n";

        echo "Convert from alpha2 to alpha3:" . $this->countryService->alpha3($alpha2)->name . "\n";
        echo "Convert from alpha3 to alpha2:" . $this->countryService->alpha2($alpha3)->name . "\n";

        echo "Convert from alpha2 to numeric code:" . $this->countryService->numericCode($alpha2) . "\n";
        echo "Convert from alpha3 to numeric code:" . $this->countryService->numericCode($alpha3) . "\n";

    //From numeric code:
        echo "From numeric code to alpha2:" . $this->countryService->fromNumericCode($numericCode)->name . "\n";
    //From numeric code:
        echo "From numeric code to alpha3:" . $this->countryService->alpha3(
            $this->countryService->fromNumericCode($numericCode)
        )->name . "\n";
    }
}

Use your own country name

use EnumCountriesIso3166\Country;
use EnumCountriesIso3166\CountryAlpha3;
use EnumCountriesIso3166\CountryService;

class MyCountryService extends CountryService
{
    public function getName(Country|CountryAlpha3 $country): string
    {
        switch ($country) {
            case Country::FR:
            case CountryAlpha3::FRA:
                return "My own naming for France";
        }

        return parent::getName($country);
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-24