bonvga/

此包已被废弃,不再维护。未建议替代包。

Maxmind GeoIP 2 工具包,用于 Symfony 2

1.1 2016-05-24 14:21 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:51:17 UTC


README

这是一个用于安装 Maxmind GeoCity2 数据库的 Symfony 2 扩展包。

要求

您需要安装 Curl 二进制包。 (https://curl.haxx.se/)

安装

  1. 将 Geoip2Bundle 添加到您的依赖项中

    // composer.json
    
    {
       // ...
       "require": {
           // ...
           "bonvga/geoip2": "1.*"
       }
    }
    
  2. 使用 Composer 下载并安装 Geoip2Bundle

    $ php composer.phar update bonvga/geoip2
    
  3. 在您的应用程序中注册扩展包

    // app/AppKernel.php
    
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Bonvga\Bundle\Geoip2Bundle\Geoip2Bundle()
        );
    }
    
  4. 可选,在 composer 过程中更新 Maxmind GeoCity2 数据库

    // composer.json
    
    "scripts": {
        "post-install-cmd": [
            "Bonvga\\Bundle\\Geoip2Bundle\\Composer\\ScriptHandler::installDatabase"
        ],
        "post-update-cmd": [
            "Bonvga\\Bundle\\Geoip2Bundle\\Composer\\ScriptHandler::installDatabase"
        ]
    },
    
    // or with command
    
    $ php app/console bonvga:geoip2_database_update
    

用法

使用 geoip2/geoip2 扩展包

    // composer requirement
    "geoip2/geoip2": "~2.0"

或者查看 https://packagist.org.cn/packages/geoip2/geoip2

    // PHP sample

    use Bonvga\Bundle\Geoip2Bundle\Lib\Geoip2Manager;
    use GeoIp2\Database\Reader;

    $reader = new Reader(Geoip2Manager::getGeoip2LiteCityDatabasePath());