snapshotpl / zf-snap-geoip
MaxMind GeoIP Module for Zend Framework 2
Installs: 12 546
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 5
Forks: 4
Open Issues: 4
Requires
- php: ^5.6 || ^7.0
- geoip/geoip: ^1.14
- zendframework/zend-console: ^2.6.0
- zendframework/zend-eventmanager: ^2.6.3 || 3.0
- zendframework/zend-modulemanager: ^2.7.2
- zendframework/zend-mvc: ^2.7.10
- zendframework/zend-servicemanager: ^2.7.8 || ^3.0
- zendframework/zend-stdlib: ^2.7.7
- zendframework/zend-view: ^2.8.1
Requires (Dev)
- phpunit/phpunit: ^5.7
- zendframework/zend-config: ^2.6.0
- zendframework/zend-i18n: ^2.7.3
- zendframework/zend-log: ^2.9.1
- zendframework/zend-serializer: ^2.8
README
Maxmind Geoip module for Zend Framework 2
Created by Witold Wasiczko
Usage
Default ZfSnapGeoip returns Record object created by current user's IP address.
In controller:
$record = $this->getServiceLocator()->get('geoip')->getRecord(); echo $record->getCity();
$record = $this->getServiceLocator()->get('geoip')->getRecord('216.239.51.99'); echo $record->getLongitude(); echo $record->getLatitude();
By view helper:
Returns city name for current IP:
<?php echo $this->geoip() ?>
Returns country name for given IP:
<?php echo $this->geoip('184.106.35.179')->getCountryName() ?>
You can also implements \ZfSnapGeoip\IpAwareInterface
interface and then use instance in service/helper:
<?php echo $this->geoip($user)->getTimezone() ?>
Avaliable getter methods via \ZfSnapGeoip\Entity\Record
:
getAreaCode()
getCity()
getContinentCode()
getCountryCode()
getCountryCode3()
getCountryName()
getDmaCode()
getLatitude()
getLongitude()
getMetroCode()
getPostalCode()
getRegion()
getRegionName()
getTimezone()
Events
Module supports \Zend\EventManager
.
How to install?
Via composer.json
{ "require": { "snapshotpl/zf-snap-geoip": "2.*" } }
and add ZfSnapGeoip
module name to application.config.php
To download data file from http://dev.maxmind.com/geoip/legacy/geolite/ use Zend\Console
(you can add this to crontab):
php index/public.php geoip download
Or use autoupdate database during install/update in composer (just add this lines to composer.json and run composer):
{ "scripts": { "post-install-cmd": [ "ZfSnapGeoip\\Composer\\ScriptHandler::downloadData" ], "post-update-cmd": [ "ZfSnapGeoip\\Composer\\ScriptHandler::downloadData" ] } }
Console usage
You can download GeoIP database from application console:
php public/index.php geoip download
There are optional parameters:
--no-clobber
Don't overwrite an existing db file,-q
Turn off output,