yamilovs/sypex-geo-bundle

An adaptation of SypexGeo library to Symfony Bundle system

Installs: 43 362

Dependents: 4

Suggesters: 0

Security: 0

Stars: 8

Watchers: 3

Forks: 10

Open Issues: 0

Type:symfony-bundle

2.0.1 2020-03-06 12:00 UTC

This package is auto-updated.

Last update: 2024-12-20 01:46:05 UTC


README

Build Status

SypexGeoBundle

This is an adaptation of Sypex Geo Library for Symfony.

Installation

Step 1: Download SypexGeoBundle using composer

Add SypexGeoBundle by running the command:

$ composer require yamilovs/sypex-geo-bundle:^2.0

Step 2: Enable the bundle

Enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Yamilovs\Bundle\SypexGeoBundle\SypexGeoBundle(),
    );
}

Step 3: Add some configurations

# app/config/config.yml

yamilovs_sypex_geo:
    mode: FILE # FILE (default) | BATCH | MEMORY
    database_path: "%kernel.root_dir%/../var/SypexGeoDatabase/SxGeoCity.dat"

If you need the proxy configuration for database update, you can add:

yamilovs_sypex_geo:
    ......
    connection:
        proxy:
            host: 'xxx.xxx.xxx.xxx'
            port: # port number
            
            # You can enable user credentials if you have them
            auth:
                user: 'your username'
                password: 'your password'

Step 4: Download necessary databases

Download necessary databases to database_path.

  • You can run php bin/console yamilovs:sypex-geo:update-database-file
  • Or download it manually from Sypex Geo City

Usage

In your controller

<?php
// src/Controller/FooController.php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Yamilovs\SypexGeo\SypexGeo;

class FooController extends Controller
{
    public function fooAction(Request $request, SypexGeo $sypexGeo)
    {
        $userIp = $request->getClientIp();
        $testIp = '88.86.218.24';

        $city = $sypexGeo->getCity($testIp, true);

        dump($city);
    }
}

Note:

Your local ip address is 127.0.0.1 and Sypex Geo cant get your city or country!

If you want to check data from specific IP address

You can run php bin/console yamilovs:sypex-geo:get-ip-data aa.bb.cc.dd