Shiny GeoIP - Adding Support For Multiple MaxMind GeoIP Databases

222 views Asked by At

I have a problem. So, I have a geoip database reading api in PHP and I wanted to add the ability to fetch data from multiple geoip2 databases in this api, but due to my lack of knowledge in PHP class structures, I can't do it. Some advice to making this happen would be great. I know I can also achieve the same result by combining the databases, but I didn't figure out how to properly do this, despite MaxMind's thorough documentation of building custom databases. I would prefer to do this via the api though, as I wanted to make a fork anyways to fit my needs. I have narrowed down the importation of the databases in the code to the following line in src/Domain/LocationDomain.php:

public function __construct()
{
    $this->pathToLocationDb = PROJECT_ROOT . 'data/GeoLite2-City.mmdb';
    $this->reader = new Reader($this->pathToLocationDb);
}

As you can see, the code imports only one database and I need it to import a second or potential third. I was playing around with it and I found that adding these lines within the function will make the api favor one database over the other:

$this->pathToLocationDb = PROJECT_ROOT . 'data/GeoLite2-ASN.mmdb';
$this->reader = new Reader($this->pathToLocationDb);

However, this isn't desirable due to me wanting both databases.

The repository in question is here: https://github.com/nekudo/shiny_geoip

0

There are 0 answers