Giter VIP home page Giter VIP logo

zfsnapgeoip's Introduction

ZfSnapGeoip Build Status Scrutinizer Code Quality

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,

zfsnapgeoip's People

Contributors

purplehexagon avatar snapshotpl avatar tdutrion avatar vincequeiroz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

zfsnapgeoip's Issues

ZF3 compatible?

Hey,
i have a question. Is this module zf3 compatible?

Best regards

Timezone?

Record entity does not contain timezone info. It would be cool if record entity contains support for timezones

GeoLiteCity.dat not being downloaded

The file is not being downloaded by composer.
Even "php public/index.php geoip download" does not create the file.
Do you have an idea what's wrong here?

Absent of possibility to get geoiprecord AND geoipdnsrecord

There should be possibility to get geoiprecord AND geoipdnsrecord that return by GeoIP_record_by_addr() and getrecordwithdnsservice().
I need the stable class for serialization. Or implement serialization.

Make getGeoip() and getRecord() public functions.
Thanks.

Encoding of getCity()?

Hi there,
I often get unrecognized characters out of the getCity() function. I have tried reencoding it to UTF-8 using
mb_convert_encoding($geo->getCity(),"UTF-8","auto"), but that sometimes generates this warning:
Warning: mb_convert_encoding(): Unable to detect character encoding in ...

Maybe if you know the encoding of the string I can reencode it more exactly...
Any ideas?

Reinvention of wheel

I recently found Geocoder library which is just too awesome and I discovered that this module can use Geocoder library to remove some duplicate code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.