wnx/php-swiss-cantons
Composer 安装命令:
composer require wnx/php-swiss-cantons
包简介
Search for Swiss Cantons by name or abbreviation.
README 文档
README
Using Javascript? Check out @stefanzweifel/js-swiss-cantons.
Installation
The easiest way to install the package is by using composer. The package requires PHP 8.2.
composer require "wnx/php-swiss-cantons"
Usage
Use the CantonManager Class to interact with this package. Below you find an example how you can use with in the Laravel Framework. Further you find all public API methods for CantonManager and Canton.
<?php use Wnx\SwissCantons\CantonManager; $cantonManager = new CantonManager(); /** @var \Wnx\SwissCantons\Canton $canton */ $canton = $cantonManager->getByAbbreviation('zh'); $canton = $cantonManager->getByName('Zurigo'); $canton = $cantonManager->getByZipcode(8000); // "Zürich" $cantonName = $canton->setLanguage('de')->getName();
CantonManager
Use the CantonManager to find a Canton. It will return a new Instance of Canton or throws an Exception if no Canton could be found for the abbreviation, name or zipcode.
getByAbbreviation()
Find a Canton by its abbreviation. See this list for available abbreviations.
$cantonManager = new Wnx\SwissCantons\CantonManager(); /** @var \Wnx\SwissCantons\Canton $canton */ $canton = $cantonManager->getByAbbreviation('GR');
getByName()
Search for a Canton by its name. The name must exactly match one of the translations of the Canton (German, French, Italian, Romansh or English).
$cantonManager = new Wnx\SwissCantons\CantonManager(); /** @var \Wnx\SwissCantons\Canton $canton */ $canton = $cantonManager->getByName('Zürich');
getByZipcode()
Returns an array of possible Cantons for a given Zipcode. (Some zipcodes are shared between multiple Cantons).
$cantonManager = new Wnx\SwissCantons\CantonManager(); /** @var \Wnx\SwissCantons\Canton[] $cantons */ $cantons = $cantonManager->getByZipcode(3005);
getByZipcodeAndCity()
Find Canton by a given zipcode and optionally by a city name.
$cantonManager = new Wnx\SwissCantons\CantonManager(); /** @var \Wnx\SwissCantons\Canton $canton */ $canton = $cantonManager->getByZipcodeAndCity(1003); $canton = $cantonManager->getByZipcodeAndCity(1290, 'Lausanne');
Canton
setLanguage($string = 'en')
Set the language, which should be used to display the name of the canton. The following languages are currently supported.
- German (
de) - French (
fr) - Italian (
it) - Romansh (
rm) - English (
en, default)
The method returns the current instance of Canton for easier method chaining.
$canton->setLanguage('rm');
$canton->setLanguage('fr')->getName();
getName()
Return the Name for the given Canton. If the method is used without calling the setLanguage() method first, it will return the name in English.
$canton->getName(); // Grisons $canton->setLanguage('de')->getName(); // Graubünden
getAbbreviation()
Return the offical abbreviation for the given Canton.
$canton->getAbbreviation(); // e.g. ZH
Cantons
This class is used internally but can also be used in your own project if you need a list of all cantons
getAll()
Returns an array containg Wnx\SwissCantons\Canton objects.
use Wnx\SwissCantons\Cantons; $cantons = (new Cantons)->getAll();
getAllAsArray($defaultLanguage = 'en')
Returns a one dimensionl array of all Cantons. The key is the abbreviation. The value will be the translated name of the Canton. The default language is English. Pass one of the valid languages to the method, to localize the names.
use Wnx\SwissCantons\Cantons; $cantons = (new Cantons)->getAllAsArray('en'); $cantonsAsArray = $cantons->getAllAsArray(); // var_dump($cantonsAsArray); // [ // 'ZH' => 'Zurich', // 'GE' => 'Geneva', // // ... // ]
Security
If you discover a security vulnerability within this package, please send an e-mail to stefan@stefanzweifel.dev. All security vulnerabilities will be promptly addressed.
Data Sources
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Credits
License
This project is licensed under the MIT License - see the LICENSE file for details.
wnx/php-swiss-cantons 适用场景与选型建议
wnx/php-swiss-cantons 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58.52k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2016 年 06 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「swiss」 「cantons」 「canton」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wnx/php-swiss-cantons 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wnx/php-swiss-cantons 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wnx/php-swiss-cantons 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Rounds store prices to 1/20th or 1/10th - ie: to 0.05 or 0.1 of your currency
Converting swiss coordinates to Lat/Long global coordinates.
Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.
Manage event blogs in the Contao backend and display them in the frontend of your website.
Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.
Bizcuit SwissQR decoding and validation library
统计信息
- 总下载量: 58.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 19
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-29