Skip to content

v7.0.0

Choose a tag to compare

@stevebauman stevebauman released this 05 Jul 19:04
· 219 commits to master since this release
88c04ff

Upgrading from v6

In version 7, the codebase has been updated with strict PHP types,
updated PHP and Laravel version requirements, an updated Driver
structure, as well as a small configuration addition.

Configuration

In version 7, location drivers can now implement an Updatable interface
that allows them to be updated using the location:update command.
Currently, only the MaxMind driver supports this.

To update your configuration file to be able to download the latest
MaxMind database file automatically, insert the below url
configuration option in your config/location.php file:

// config/location.php

return [
    'maxmind' => [
        // ...
        
        'local' => [
            // ...
            
+            'url' => sprintf('https://download.maxmind.com/app/geoip_download_by_token?edition_id=GeoLite2-City&license_key=%s&suffix=tar.gz', env('MAXMIND_LICENSE_KEY')),
        ],
    ],
];

Once done, you may execute the below artisan command to download the latest .mmdb file:

php artisan location:update

Drivers

In version 7, the codebase has been updated with strict PHP
types, updated PHP and Laravel version requirements,
and an updated Driver structure.

If you have created your own custom driver implementation,
you must update it to use the base Driver or HttpDriver class.

If you're fetching a location using an HTTP service, it
may be useful to extend the HttpDriver to reduce
the code you need to write:

namespace App\Location\Drivers;

use Illuminate\Support\Fluent;
use Stevebauman\Location\Position;
- use Stevebauman\Location\Drivers\Driver;
+ use Stevebauman\Location\Drivers\HttpDriver;

- class MyDriver extends Driver
+ class MyDriver extends HttpDriver
{
-    public function url($ip)
+    public function url(string $ip): string;
    {
        return "http://driver-url.com?ip=$ip";
    }
    
-    protected function process($ip)
-    {
-        return rescue(function () use ($ip) {
-            $response = json_decode(file_get_contents($this->url($ip)), true);
-            
-            return new Fluent($response);
-        }, $rescue = false);
-    }

-    protected function hydrate(Position $position, Fluent $location)
+    protected function hydrate(Position $position, Fluent $location): Position;
    {
        $position->countryCode = $location->country_code;

        return $position;
    }
}

Pull Request

https://github.com/stevebauman/location/pull/142