yiicod/yii2-geo

Yii GEO helper/finder

Installs: 1 175

Dependents: 0

Suggesters: 0

Security: 0

Stars: 7

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

1.1.0 2018-07-24 15:20 UTC

This package is auto-updated.

Last update: 2024-10-27 00:48:58 UTC


README

Latest Stable Version Total Downloads Scrutinizer Code QualityCode Climate

This extension will help you to find user country and country code. It use two online and one offline system for find information about user. You no need worry what system will use because all of this will do one component GeoFinder

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiicod/yii2-geo "*"

or add

"yiicod/yii2-geo": "*"

to the require section of your composer.json.

Config for frontend

'container' => [
    'singletons' => [
        \yiicod\geo\storages\StorageInterface::class => [
            'class' => \yiicod\geo\storages\CacheStorage::class,
        ],
    ],
],
'components' => [
    'geoFinder' => [
        'class' => yiicod\geo\components\GeoFinder::class,
        'gettersList' => [
            [
                'class' => \yiicod\geo\adapters\geoIp2\GeoIp2CityAdapter::class,
                'databaseConfig' => [
                    'class' => \yiicod\geo\adapters\geoIp2\GeoIp2Database::class,
                    'databaseAlias' => '@frontend/runtime',
                ],
            ],
            [
                'class' => \yiicod\geo\adapters\ipstack\IpstackAdapter::class,
                'apiKey' => 'API-key'
            ],
            [
                'class' => \yiicod\geo\adapters\geoPlugin\GeoPluginAdapter::class,
            ],
        ],
    ],
],

Usage

\yiicod\geo\GeoGetter::getCountryName($ip)
\yiicod\geo\GeoGetter::getCountryCode($ip)
\yiicod\geo\GeoGetter::getRegionName($ip),
\yiicod\geo\GeoGetter::getRegionCode($ip),
\yiicod\geo\GeoGetter::getCity($ip),
\yiicod\geo\GeoGetter::getLatitude($ip),
\yiicod\geo\GeoGetter::getLongitude($ip),