定制 omisai/php-countries 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

omisai/php-countries

Composer 安装命令:

composer require omisai/php-countries

包简介

PHP package to provide countries data

README 文档

README

License Latest Stable Version PHP Version Require Test

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,total area in square kilometers, country's capital city, continent code.

Features

  • Easy retrieval of country names and codes, total area in square kilometers, 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, Portuguese, Dutch, Danish, Swedish, Norwegian, Polish, Czech, Slovak, Slovenian and Croatian 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->getCountriesArea(); // ['country_name' => 'country_area']

$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->area; // "337,030.0"
$europe->hu; // "Finnország"
$europe->name; // "Finland"
$europe->getName('it'); // "Finlandia"

Changelog

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

Testing

./vendor/bin/pest

# or

composer test

Contributing

Please see CONTRIBUTING.md for details on how to contribute to this project.

Security

Please see SECURITY.md for details on reporting security vulnerabilities.

License

This package is open-sourced software licensed under the MIT license.

Sponsoring

If you find this package useful, please consider sponsoring the development: Sponsoring on GitHub

Your support helps us maintain and improve this open-source project!

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固