定制 snapshotpl/zf-snap-geoip 二次开发

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

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

snapshotpl/zf-snap-geoip

最新稳定版本:2.6.0

Composer 安装命令:

composer require snapshotpl/zf-snap-geoip

包简介

MaxMind GeoIP Module for Zend Framework 2

README 文档

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.

Class Event name Description Params
ZfSnapGeoip\Controller\ConsoleController downloadAction.exists If no-clobber is enabled and file exists path (to dat file)
ZfSnapGeoip\Controller\ConsoleController downloadAction.pre Before unzip file path (to dat file), response (gziped response object)
ZfSnapGeoip\Controller\ConsoleController downloadAction.post After unzip file path (to dat file)
ZfSnapGeoip\Service\Geoip getIp After read IP ip (ip address)
ZfSnapGeoip\Service\Geoip getRecord After created record record (instance of ZfSnapGeoip\Entity\RecordInterface)
ZfSnapGeoip\Service\Geoip getRegions After first loading regions names regions

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,

统计信息

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

GitHub 信息

  • Stars: 15
  • Watchers: 4
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2013-07-15