承接 omisai/php-countries 相关项目开发

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

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

omisai/php-countries

最新稳定版本:1.3.1

Composer 安装命令:

composer require omisai/php-countries

包简介

PHP package to provide countries data

README 文档

README

License Latest Stable Version PHP Version Require

PHP Countries Package

The PHP Countries Package provides a convenient and object-oriented approach to working with country data. Designed to integrate country information into any PHP applications with ease. This package offers easy access to country names, ISO 3166-1 alpha-2 code, ISO 3166-1 alpha-3 code, ISO 3166-1 numeric code, FIPS code, phone dial, country's capital city, continent code.

Features

  • Easy retrieval of country names and codes, capital city and/or continent.
  • Object-Oriented Programming (OOP) approach for better data management and integration.
  • Lightweight and simple to integrate into any PHP project. (8.1+)
  • Currently supporting English, Hungarian, German, Spanish, Italian, French and Portuguese languages.
  • Future support for multiple locales, making it versatile for international applications.

Installation

The PHP Countries Package can be easily installed via Composer.

composer require omisai/php-countries

Usage

After installing the package, you can begin to work with any country data. You can work with country model directly or access all of them through a Collection class.

/**
 * Access through the Collection
 *
 * Consider using the Collection class, if you
 * plan to register it to a service container.
 * It eagerly loads all the countries.
 */
use Omisai\Countries\Collection;

$collection = new Collection();
$countries = $collection->getCountries();

/**
 * Shorthand to use the default english locale
 */
$countries[4]->name; // "Finland"

/**
 * Or using different locale
 */
$countries[4]->getName('fr'); // "Finlande"

/**
 * Search for a specific country based on different criteria
 */
$collection->getCountryByAlpha2('FI'); // Omisai\Countries\Models\Finland
$collection->getCountryByAlpha3('FIN'); // Omisai\Countries\Models\Finland
$collection->getCountryByNumeric('246'); // Omisai\Countries\Models\Finland
$collection->getCountryByFipCode('FI'); // Omisai\Countries\Models\Finland
$collection->getCountryByDial('358'); // Omisai\Countries\Models\Finland
$collection->getCountryByCapital('Helsinki'); // Omisai\Countries\Models\Finland
$collection->getCountryByName('Finland'); // Omisai\Countries\Models\Finland
$collection->getCountryByName('Finlande', "fr"); // Omisai\Countries\Models\Finland

/**
 * Get only a part of data from the countries
 */
$collection->getCountriesAlpha2(); // ['country_name' => 'country_alpha2']
$collection->getCountriesAlpha3(); // ['country_name' => 'country_alpha3']
$collection->getCountriesNumeric(); // ['country_name' => 'country_numeric']
$collection->getCountriesFipCode(); // ['country_name' => 'country_fipCode']
$collection->getCountriesDial(); // ['country_name' => 'country_dial']

$collection->getCountriesAlpha2('fr'); // ['fr:country_name' => 'country_alpha2'] -> ['Finlande' => 'FI']

$collection->getCountriesByContinent('EU'); // [Omisai\Countries\Models\Finland, Omisai\Countries\Models\Hungary, ...]

/**
 * Use any country directly
 */
use Omisai\Countries\Models\Finland;

$europe = new Finland();
$europe->alpha2; // "FI"
$europe->alpha3; // "FIN"
$europe->numeric; // "246"
$europe->fipCode; // "FI"
$europe->dial; // "358"
$europe->capital; // "Helsinki"
$europe->continent; // "EU"
$europe->hu; // "Finnország"
$europe->name; // "Finland"
$europe->getName('it'); // "Finlandia"

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Testing

./vendor/bin/pest

# or

composer test

Security

If you discover any security-related issues, please email security@omisai.com instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-27