Giter Site home page Giter Site logo

geoip2's People

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

geoip2's Issues

no Command efined

i ma using symofny 4
and try to download database with bin/console geoip2:update
but getting There are no commands defined in the "geoip2" namespace.

how to inject service in symfony 4?

Hi!

I need to inject the service into the controller method like this:

namespace App\Controller;

use GeoIp2\Database\Reader;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class ApiController extends AbstractController
{

  public function someAction(Reader $reader)
  {
    dd($reader);
  }
}

but i'm have this error:

"Cannot autowire argument $reader of \"App\\Controller\\ApiController::someAction()\": it references class \"GeoIp2\\Database\\Reader\" but no such service exists. You should maybe alias this class to the existing \"geoip2.reader\" service."

is it possible to do it somehow?

thanx

Issue with Symfony 4.4 integration - The file var/cache/dev/GeoLite2-City.mmdb does not exist or is not readable

Hi there,

I've followed the steps to integrate the librairy in my project.
I've created a Service to use it in my code like so:

// src/Service/GeoipLib.php

namespace App\Services;

use GeoIp2\Database\Reader;

class GeoIPLib
{
    private $reader;

    public function __construct(Reader $reader)
    {
        $this->reader = $reader;
    }

    public function getCity($ip)
    {
        // get a GeoIP2 City model
        $record = $this->reader->city($ip);
        return $record->mostSpecificSubdivision->name;
    }

    public function getCountry($ip)
    {
        // get a GeoIP2 City model
        $record = $this->reader->city($ip);
        return $record->country->isoCode;
    }

    public function getPostalCode($ip)
    {
        // get a GeoIP2 City model
        $record = $this->reader->city($ip);
        return $record->postal->code;
    }
}

and my config file is as follow:

# Read the README file for more detailed configuration information
# https://github.com/gpslab/geoip2
gpslab_geoip:
    # You should specify your personal licence key
    license: 'XXXXX'

    # Edition ID of database you need
    edition: 'GeoLite2-City'

    url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=XXXXX&suffix=tar.gz'

If I follow the url, it does download the file so the key seems good to me.

However, when I'm trying to use the librairy, I'm getting the following error message:

The file var/cache/dev/GeoLite2-City.mmdb does not exist or is not readable

Indeed, it does not exist in the cache folder.

Please help.
Thank you.

Need update Travis CI config

Some options in Travis CI config is outdated

root: deprecated key sudo (The key sudo has no effect anymore.)
root: missing os, using the default linux
root: key matrix is an alias for jobs, using jobs

DependencyInjection for ReaderFactory does not work in Symfony 5.2

Hello,

Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\RuntimeException: "Cannot autowire argument $readerFactory of "App\Controller\Test\TestController::geoip()": it references class "GpsLab\Bundle\GeoIP2Bundle\Reader\ReaderFactory" but no such service exists." at C:\Projects\testProject\vendor\symfony\dependency-injection\Container.php line 435
Hide context    Hide trace
[▼
  "exception" => Symfony\Component\DependencyInjection\Exception\RuntimeException {#10076 ▶}
]
{▼
  C:\Projects\testProject\vendor\symfony\dependency-injection\Container.php:435 {▼
    Symfony\Component\DependencyInjection\Container->getService($registry, string $id, ?string $method, $load) …
    › if (\is_string($load)) {
    ›     throw new RuntimeException($load);
    › }
  }
...

Thanks
Rico

Old urls's to databases not working

Maxmind changed their policy and user agreements about using their data so old urls like
https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
are not working anymore.
Any suggestions to move to other alternative or are you planning to fix this?

Issue with Symfony 4.4 integration - Resource temporarily unavailable

Hi there,

After I have followed the steps and added this bundle to my project, everything was working fine. But when I tried to update the database with the command ("php bin/console geoip2:update") I have received an error. Do you have any idea what could make this issue.

In Filesystem.php line 179:

Failed to remove file "C:\Users\user\AppData\Local\Temp/603784fb9d6e84.54757459_GeoLite2.tar": unlink(C:\Users\user\AppData\Local\Temp/603784fb9d6e84.54757459_GeoL
ite2.tar): Resource temporarily unavailable

Thank You!

Out of memory updating GeoLite2-City

Since July 22nd, geoip2:update runs out of memory when updating the GeoLite2-City edition because the current memory usage exceeds the default 128MB memory limit on Fedora:Memory Usage: 21795872 Memory Peak Usage: 146951168

$zip = new \PharData($tmp_zip);

Two solutions:

  1. Add ini_set('memory_limit', '256M'); before opening the archive with PharData. Not a great solution in my opinion.
  2. Use splitbrain/php-archive to reduce memory usage from 147MB to 18MB: Memory Usage: 17999088 Memory Peak Usage: 18098424 by replacing

// decompress gz file
$zip = new \PharData($tmp_zip);
$tar = $zip->decompress();
$this->logger->debug('Decompression complete');
$this->logger->debug(sprintf('Extract tar file to %s', $tmp_untar));
// extract tar archive
$tar->extractTo($tmp_untar);
unset($zip, $tar);
$this->logger->debug('Tar archive extracted');

with:

use splitbrain\PHPArchive\Tar;
...
        // extract tar.gz archive
        $tar = new Tar();
        $tar->open($tmp_zip);
        $tar->extract($tmp_untar);
        $tar->close();
        unset($tar);

        $this->logger->debug(sprintf('Tar archive extracted to %s', $tmp_untar));

How to use Service injection in Symfony 6 properly

Hi, thanks for the library!

I`m having quite some trouble understanding what the heck is going on. Basically, I want a service that I can use in Controllers and EventListeners.

After checking the issues here and comments, you mentioned to declare:

GeoIp2\Database\Reader:
        alias: 'geoip2.reader'
        public: true

However, this is not needed apparently. The moment you pass use GeoIp2\Database\Reader into the constructor, the following gets injected:

[ContainerLx2Tlzg\Reader_5400306 - GeoIp2\Database\Reader@proxy](http://.../_profiler/open?file=var\cache\dev\ContainerLx2Tlzg\Reader_5400306.php&line=7#line7) {#643 ▼
  -valueHolder16a63: null
  -initializer876c2: [Closure(&$wrappedInstance, LazyLoadingInterface $proxy)](http://.../_profiler/open?file=var\cache\dev\ContainerLx2Tlzg\**getGeoip2_Database_CityReaderService**.php&line=22#line22) {#647 ▼
    class: "[ContainerLx2Tlzg\getGeoip2_Database_CityReaderService](http://.../_profiler/open?file=var\cache\dev\ContainerLx2Tlzg\getGeoip2_Database_CityReaderService.php&line=11#line11)"
    use: {▼
      $container: ContainerLx2Tlzg\App_KernelDevDebugContainer {#55 …}
    }
  }

As above the City reader gets injected automatically, and I have no way of getting the ASN reader for example. I have also commented out default_database but without any effect.

So back to my question, how to use your library properly and as intended?

The requirement is quite simple:

  • Be able to use any reader in Controllers, EventListeners without injecting the ReaderFactory, just use the already there service.

Many thanks!

Paid edition's of the database aren't allowed as "edition" value

Thanks to this PR #56 you can't choose a paid edition

So please add the following possible values:

  • GeoIP2-City
  • GeoIP2-Country

PS: Work around for now:

  default_database: 'default'
  databases:
    default:
      edition: 'GeoLite2-City'
      license: '<fill your license>' 
      # Paid version:
      url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoIP2-City&suffix=tar.gz&license_key=<fill your license>'```

Update will throw an UnexpectedValueException

3.4.47 Symfony version
Update will throw an UnexpectedValueException In MaxMindDownloader.php line 88:
Cannot decompress zip-based archives with whole-archive compression
Config:

gpslab_geoip:
    license: 'xxx'
    locales: [ 'en' ]
    default_database: 'city'
    databases:
        asn:
            edition: 'GeoLite2-ASN'
            url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN-CSV&license_key=xxx&suffix=zip'
            path: '%kernel.project_dir%/var/GeoLite2-ASN.mmdb'
        city:
            edition: 'GeoLite2-City'
            url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&license_key=xxx&suffix=zip'
            path: '%kernel.project_dir%/var/GeoLite2-City.mmdb'
        country:
            edition: 'GeoLite2-Country'
            url: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=xxx&suffix=zip'
            path: '%kernel.project_dir%/var/GeoLite2-Country.mmdb'

Command:
php bin/console geoip2:update asn -vvv

zlib:

ZLib Support => enabled
Stream Wrapper => compress.zlib://
Stream Filter => zlib.inflate, zlib.deflate
Compiled Version => 1.2.11
Linked Version => 1.2.11

Phar:

Phar: PHP Archive support => enabled
Phar API version => 1.1.1
Phar-based phar archives => enabled
Tar-based phar archives => enabled
ZIP-based phar archives => enabled
gzip compression => enabled
bzip2 compression => disabled (install ext/bz2)
Native OpenSSL support => enabled

PHPStan error

Line src/Downloader/MaxMindDownloader.php
82 Call to an undefined method object::extractTo().
$zip = new \PharData($tmp_zip);
$tar = $zip->decompress();
$tar->extractTo($tmp_untar);

This is a false error because \Phar::decompress() return a \Phar.

Error in PHPStan phpstan/phpstan-src#114. Waiting for release this fix.

Unrecognized option "path" under "gpslab_geoip"

I've just started to configure your package, and it seems you cannot configure the path as per the documentation:

In ArrayNode.php line 314:
  Unrecognized option "path" under "gpslab_geoip". Available options are "databases", "default_database", "license", "locales".

Please update the documentation to inform people where to put the path key:

gpslab_geoip:
    path: '%kernel.project_dir%/var/GeoLite2-City.mmdb'

To:

databases:
   city:
       edition: 'GeoLite2-City'
       path: '%kernel.project_dir%/var/GeoLite2-City.mmdb'

Thanks

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.