kslimani/laravel-geo
Composer 安装命令:
composer require kslimani/laravel-geo
包简介
Laravel Geo.
README 文档
README
Laravel Geo
A simple service provider to work with locales, countries and currencies.
It uses the following dependencies :
- florianv/laravel-swap
- kslimani/geo-list (tiny version of umpirsky's projects)
- maxmind/MaxMind-DB-Reader-php
- moneyphp/money
Installation
use Composer to add the package to your project's dependencies :
composer require kslimani/laravel-geo
Note: Swap uses HTTPlug abstraction which may require additional dependencies. For example using Curl :
composer require php-http/curl-client nyholm/psr7 php-http/message
Optionally, adds the Geo facade in config/app.php :
'aliases' => [ // ... 'Geo' => Sk\Geo\Facades\Geo::class, ];
Publish the configuration file config/geo.php :
php artisan vendor:publish --provider="Sk\Geo\GeoServiceProvider" --tag="config"
Optionally, publish Swap service provider configuration file :
php artisan vendor:publish --provider="Swap\Laravel\SwapServiceProvider"
Quick usage
use Sk\Geo\Facades\Geo; // Get country code from ip address (US) $countryCode = Geo::location()->ipCountry('8.8.8.8'); // Get country name (United States) $countryName = Geo::locale()->country($countryCode); // Get country language code (en) $languageCode = Geo::locale()->countryLanguage($countryCode); // Get country language name (English) $languageName = Geo::locale()->language($languageCode); // Get country currency code (USD) $currencyCode = Geo::locale()->countryCurrency($countryCode); // Get country currency name (US Dollar) $currencyName = Geo::locale()->currency($currencyCode); // Make money amount $fiveDollars = Geo::money()->make('500', $currencyCode); // Get amount converted to Euro $euroAmount = Geo::money()->convert($fiveDollars, 'EUR'); // Get formatted amount ("Intl" formatter) $intlFormattedAmount = Geo::money()->format($euroAmount); // Get formatted amount ("Decimal" formatter) $decFormattedAmount = Geo::money()->formatDec($euroAmount); // Parse "Decimal" formatted amount $newEuroAmount = Geo::money()->parse($decFormattedAmount, 'EUR'); // Decompose money amount $keyValueArray = Geo::money()->decompose($fiveDollars); // [ // "locale" => "en" // "subunit" => 2 // "sign" => "+" // "unsigned_part" => "5" // "decimal_part" => "00" // "grouping_separator" => "," // "decimal_separator" => "." // "symbol" => "$" // ] // Get all countries (country code -> name associative array) $countries = Geo::locale()->countries(); // Get all languages (language code -> name associative array) $languages = Geo::locale()->languages(); // Get all currencies (currency code -> name associative array) $currencies = Geo::locale()->currencies(); // All methods returning a name accept an optional locale (default is application locale) Geo::locale()->country('US', 'es'); // 'Estados Unidos' Geo::locale()->language('en', 'de') // 'Englisch' Geo::locale()->currency('USD', 'ru') // 'Доллар США' Geo::locale()->countries('zh') // [ 'BT' => '不丹', 'TL' => '东帝汶', ... ] Geo::money()->format($fiveDollars, 'fr') // '5,00 $US' Geo::money()->decompose($amount, 'fr'); // [ 'locale' => 'fr', ... ] // Get instances using app helper $location = app('geo.location'); $locale = app('geo.locale'); $money = app('geo.money');
Console commands
This package also provides some Artisan console commands :
geo:exchange Simple currency converter
geo:info Display geo data for ip address
geo:list Display countries with default language and currency
geo:maxmind Display Maxmind DB countries with matched geo country name
Note: geo:list and geo:maxmind are mainly used for package development.
kslimani/laravel-geo 适用场景与选型建议
kslimani/laravel-geo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25.66k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2017 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geo」 「locale」 「currency」 「laravel」 「country」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kslimani/laravel-geo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kslimani/laravel-geo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kslimani/laravel-geo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Package for convenient work with Laravel's localization features
Show geo marker on a mapbox map
Show geo shape on a mapbox map with drawing capabilities
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Fixer.io data provider for Peso
A Lithium plugin with additional g11n resources constituting the Lithium Locale Data Repository.
统计信息
- 总下载量: 25.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-19